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" ?>标签:servicemodel,暴露,EssentialWCF,serviceHost,typeof,behavior,new,数据交换,节点 From: https://blog.51cto.com/u_15870687/5837404
< 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 >