我在App.Config文件中定义了两个端点为
<system.serviceModel>
<services>
<service
name="HostDirectAddress.ITestService"
behaviorConfiguration="behaviorConfig">
<endpoint
address="net.tcp://localhost:9000/ITestService"
binding="netTcpBinding"
contract="HostDirectAddress.ITestServiceContract"/>
<endpoint
address="http://localhost:9000/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorConfig">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我的客户致电
static void Main(string[] args)
{
ServiceHost host =
new ServiceHost(typeof(HostDirectAddress.ITestService));
host.Open();
Console.WriteLine("....Service is Ready to Consume...");
Console.ReadLine();
}
我尝试启动主机时收到以下错误
ServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但没有http基址。提供http基址或将HttpGetUrl设置为绝对地址。
如何解决?
答案 0 :(得分:5)
错误消息告诉您如何解决它!
1)添加基地
<service
name="HostDirectAddress.ITestService"
behaviorConfiguration="behaviorConfig">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9000/" />
</baseAddresses>
</host>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
OR:
2)在服务行为中定义一个固定且完整的HTTP地址:
<behavior name="behaviorConfig">
<serviceMetadata
httpGetEnabled="true"
httpGetUrl="http://localhost:9000/mex" />
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
做一个或另一个 - 事情应该运作得很好。