你不用配置文件当然可以发布了,你在创建ServiceHost的时候已经传入了base address,这时就不会再使用配置文件中的值了。
你好,是不是用IE打开地址找不到任何信息,你得公开元素据,配置如下
<services>
<service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address="http://localhost:8000/ServiceModelSamples/service" binding="wsHttpBinding" bindingConfiguration="" contract="Microsoft.ServiceModel.Samples.ICalculator"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
用代码实现如下
ServiceMetadataBehavior metabehavior = new ServiceMetadataBehavior();
ServiceBehaviorAttribute behaviorAttribute = new ServiceBehaviorAttribute();
behaviorAttribute.IncludeExceptionDetailInFaults = true;
metabehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(metabehavior);
这样你就可以访问到服务了