今天我建了一个WCF测试库,系统自动生成的服务契约没有处理,直接在下面添加了一个双工契约。
但是测试运行的时候报了不少错误,最后一个错误是这样的:
System.InvalidOperationException: “http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/Service1/”处带有协定“"ICalculatorDuplex"”的 ChannelDispatcher 无法打开其 IchannelListener。 ---> System.InvalidOperationException: “http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/Service1/”处带有协定“"IssueAndRenewSession"”的 ChannelDispatcher 无法打开其 IchannelListener。 ---> System.InvalidOperationException: “http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/Service1/”处带有协定“"SecurityNegotiationContract"”的 ChannelDispatcher 无法打开其 IchannelListener。 ---> System.InvalidOperationException: 已经存在 URI“http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/Service1/”的注册。
调试了一会才确定是配置文件的问题,首先,两个服务契约,配置文件里面就应该有两个service配置项,
service配置项的名称要区分开,地址也不一样,如下:
<service name="WcfSvrLib_Test1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址相对于上面提供的基址-->
<endpoint address="" binding="basicHttpBinding" contract="WcfSvrLib_Test1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
<service name="WcfSvrLib_Test1.CalculatorDuplex">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfSvrLib_Test1/CalculatorDuplex/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址相对于上面提供的基址-->
<endpoint address="" binding="wsDualHttpBinding" contract="WcfSvrLib_Test1.ICalculatorDuplex">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>