弄了一上午,终于把使用NetTcpBinding的双工通讯给弄清楚了,也算是对wcf有所掌握了,为了解决穿透防火墙的问题,所以决定尝试一下WsDualHttpBinding的双工通信,结果问题来了。。。
“无法注册 URL http://+:8735/Service/。另一应用程序已使用 HTTP.SYS 注册了该 URL。”
晕了一种个下午,百度、Google、雅虎,肯了n多e文之后终于找到答案了!为了纪念一下这个问题,特意吧好久不写的blog又翻出来了。
就罗嗦到这里,下面公布正解!!
很多网上的帖子都提到了要在客户端配置文件中写入类似于;
<wsDualHttpBinding>
<binding clientBaseAddress="http://127.0.0.1:12345/Service/" /binding>
<wsDualHttpBinding>
相信很多善良的朋友也和我一样,把服务器端的配置原样超了下来,其实这就是问题所在。因为我们这是在本地模拟双工操作,所以要单独使用另外一个端口与服务器通信所,以此处切不可与服务器使用相同的端口,将此处的12345端口改成其他任意一个没有被使用的端口号就可以解决问题。同时应该注意的是,每开一个客户端程序就应该在客户端使用一个新的端口。
附上我的客户端配置写法,供备案参考(注意两处红色字体处的不同):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IServiceSample" closeTimeout="00:01:00" clientBaseAddress="http://127.0.0.1:11112/Service/"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1:12345/Service/"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IServiceSample"
contract="ServiceReference1.IServiceSample" name="WSDualHttpBinding_IServiceSample">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>