0
点赞
收藏
分享

微信扫一扫

基础(暴露元数据交换节点)


1、原理

默认情况下,WCF服务不暴露MEX终结点

2、代码申明


   ServiceHost serviceHost =   new   ServiceHost(  typeof  (StockService),   new   Uri( "http://localhost:8000/EssentialWCF"  ));  
serviceHost.AddServiceEndpoint( typeof (IStockService), new BasicHttpBinding(), "" );
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(behavior);
serviceHost.AddServiceEndpoint( typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex" );
serviceHost.Open();

 


3、配置文件中申明

<?  xml   version  =  "1.0"   encoding  =  "utf-8"   ?>
< configuration >
< system.servicemodel >
< services >
< service name = "EssentialWCF.StockService" behaviorConfiguration = "myServiceBehavior" >
< host >
< baseaddresses >
< add baseaddress = "http://localhost:8000/EssentialWCF" />
</ baseaddresses >
</ host >
< endpoint address = "" binding = "basicHttpBinding" contract = "EssentialWCF.IStockService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</ service >
</ services >
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</ system.servicemodel >
</ configuration >

举报

相关推荐

0 条评论