![](/img/trans.png)
[英]WCF trying to expose a nettcp endpoint; TCP error code 10061: No connection could be made because the target machine actively refused it
[英]WCF - No endpoint listening at http localhost + No connection could be made because the target machine actively refused it => external network
我在控制台中托管WCF服務時遇到問題。 試圖在此處搜索,但即使與此處的其他問題相似,也無法找到此問題的解決方案。
托管非常簡單。
C#-主機
WCFSrv = new WCFService();
WCFSrvHost = new ServiceHost(typeof(WCFService));
udaWCFSrvHost.Open();
配置:
<system.serviceModel>
<services>
<service name="WCF_Service.WCFService">
<endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:23456/WCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicTimeouts" closeTimeout="00:00:30" openTimeout="00:00:30"
receiveTimeout="00:00:30" sendTimeout="00:00:30" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
我可以從本地主機通過WcfTestClient到達服務並調用服務提供的方法。
我可以通過WcfTestClient從同一網絡訪問服務,但是無法調用服務提供的方法。 一旦嘗試調用方法,我將收到錯誤消息:
There was no endpoint listening at http://localhost:23456/WCFService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
...
Inner Exception:
No connection could be made because the target machine actively refused it 127.0.0.1:23456
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
我試圖檢查是否有端口23456打開,並且應用程序正在通過netstat -an在該端口上偵聽,並且端口23456已打開並正在偵聽。
當我嘗試修改基址(而不是localhost:23456時,我在網絡中放置了服務器的真實IP,例如10.xx.xx.xx)時,我也能夠調用方法,但這只是內部解決方案的解決方法。
服務器和端口應向外部網絡開放,並可以通過Internet訪問。 我嘗試從Internet獲得服務,並且能夠從Internet獲得服務(證明端口已打開),但由於上述問題,面臨相同的問題=>無法調用方法。
有沒有人遇到過同樣的問題,能為我提供幫助嗎?
在評論中回答,出於完整性考慮。
正確檢查服務器上的客戶端配置點,而不是本地主機。
我是WCF的新手,但是最近我也遇到了同樣的問題。 我剛剛在客戶端項目中創建了一個配置文件,並在其中寫入了端點的地址:
<system.serviceModel>
<services>
<service name="WCF_Service.WCFService">
<endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:23456/WCFService/" />
</baseAddresses>
</host>
</service>
</services>
您可以使用以下參考: http : //dotnetmentors.com/how-to-host-wcf-service-in-iis-7.aspx
在我看來,觀點非常有用。 如果不起作用,請嘗試重新創建項目。
聽起來您綁定到錯誤的IP地址,請嘗試以下操作:
<host>
<baseAddresses>
<add baseAddress="http://0.0.0.0:23456/WCFService/" />
</baseAddresses>
</host>
使用0.0.0.0代替localhost會將您的服務綁定到該主機上的所有IP。
感謝大家的支持。
我的問題的解決方案:
不要使用WcfTestClient從外部網絡測試服務,至少就我而言,我遇到了問題中所述的問題。
當您將服務托管在IIS之外時,為初學者提供簡單的建議
M.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.