WCF异常:HTTP 无法注册,另一应用程序正在使用 TCP 端口 80
今天,調試服務的時候,忽然拋了個異常。異常信息是:"HTTP 無法注冊 URL http://+/Temporary_Listen_Addresses/144ff7cb-10a4-4836-b76a-1a516da4ebda/,因為另一應用程序正在使用 TCP 端口 80。"
原來,主要是因為默認80端口已經被其他程序占用。所以WCF服務在設置默認的綁定結點時會拋異常。
解決方法如下:
在客戶端代碼中設置綁定的地址。代碼如下:
?InstanceContext?instanceContext?=?new?InstanceContext(new?CallbackHandler());
?var?client?=?new?ServiceReference2.CalculatorClient(instanceContext);
?WSDualHttpBinding?ws?=?(WSDualHttpBinding)client.Endpoint.Binding;
?ws.ClientBaseAddress?=?new?Uri(http://localhost:30001/);//設定綁定的地址
?Console.WriteLine("Press?<ENTER>?to?terminate?client?once?the?output?is?displayed.");
?Console.WriteLine();
?double?value1?=?100.00D;
?client.AddTo(value1);
?client.Clear();
?Console.ReadLine();
?client.Close();
此外,還可以通過更改客戶端的服務配置文件,設置綁定的地址來解決。如下:
?<bindings>
??????<wsDualHttpBinding>
????????<binding?name="WSDualHttpBinding_ICalculator"?closeTimeout="00:01:00"?clientBaseAddress="http://localhost:30001/"
????????????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>
這樣,服務就可以正常了。
? ? 本文轉自風車車 ?博客園博客,原文鏈接:http://www.cnblogs.com/xray2005/archive/2010/01/13/1646327.html,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的WCF异常:HTTP 无法注册,另一应用程序正在使用 TCP 端口 80的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery日期弹出选择框Datepic
- 下一篇: keepalived高可用集群技术介绍及