我得到一个:
http 400 错误请求
仅当我在端点上使用相对地址时才会出错。
如果我从地址中删除“基本”,我可以毫无问题地查看 WSDL 定义:
http://localhost:8001/Test/
但是只要我添加“基本”并打开浏览器并输入:
http://localhost:8001/Test/basic
我得到了错误。
这是我的配置:
<system.serviceModel>
<services>
<service name="HostConsole.ContactService"
behaviorConfiguration="ServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:8001/Test/"/>
</baseAddresses>
</host>
<endpoint address="basic"
binding="basicHttpBinding"
contract="HostConsole.IContactService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
服务主机:
ServiceHost host = new ServiceHost(typeof(ContactService));
try {
host.Open();
foreach (ServiceEndpoint se in host.Description.Endpoints) {
Console.WriteLine(string.Format(
"Address: {0}",
se.Address.Uri.AbsoluteUri));
}
Console.WriteLine("Enter to close");
Console.ReadLine();
host.Close();
}
catch (Exception ex) {
host.Abort();
Console.WriteLine(ex.Message);
Console.ReadLine();
}