2011-09-21 18 views
0

我有一個WCF服務託管在Windows服務中,我可以連接到它並在使用同一臺計算機時正常使用它的服務,但是當我嘗試在遠程計算機上運行我的客戶端時,它會超時並且無法連接。我想我可以用服務機器的IP而不是本地主機來更新客戶端的app.config文件,但那不起作用。下面是客戶端的app.config:如何設置我的WCF服務,以便能夠被遠程客戶端訪問

<system.serviceModel> 
<bindings> 
    <wsDualHttpBinding> 
    <binding name="WSDualHttpBinding_IWCFService" closeTimeout="00:01:00" 
     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://192.168.1.141:8731/Design_Time_Addresses/WCF/WCFService/" 
    binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWCFService" 
    contract="WCFService.IWCFService" name="WSDualHttpBinding_IWCFService"> 
    <identity> 
     <dns value="192.168.1.141" /> 
    </identity> 
    </endpoint> 
</client> 

這裏是serivice的的app.config:

<system.serviceModel> 
<services> 
    <service name="WCF.WCFService" behaviorConfiguration="WCFBehavior"> 
    <endpoint address="" binding="wsDualHttpBinding" contract="WCF.IWCFService"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    <endpoint 
     address="mex" 
     binding="mexHttpBinding" 
     bindingConfiguration="" 
     contract="IMetadataExchange"/> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="WCFBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

有什麼我需要做的在服務端允許遠程連接,或者我只是沒有正確配置客戶端?

+2

Nieve問題...你確定事先關閉了防火牆嗎?如果它已經啓動,並且端口沒有暴露過去(localhost),那麼您將無法連接。 –

回答

3

這可能看起來像一個簡單的建議,但你檢查了服務器上的防火牆,以確保它不會阻止通信?我花了三天把我的頭撞到牆上,直到我注意到這一點。

+0

我沒有在服務器上啓用Windows防火牆 – Brian

+0

我確實在客戶機上有它。我把它關掉了,它工作了!謝謝。 – Brian

0

這似乎是你從家裏根據你的192地址做這件事。

您需要在路由器和Windows防火牆中打一個整體才能啓動。之後,如果你想訪問你的房子外面,你應該嘗試使用DynDNS僞造一個靜態IP來託管服務。

+0

我想從我自己的局域網內訪問它,所以我不需要做任何端口轉發 – Brian

0

你能telnet到你的服務?如果它不是防火牆問題,我懷疑是來自服務安全。由於它配置爲通過Windows憑據進行身份驗證,這需要您的服務和客戶端位於相同的域中,如果我錯了,請糾正我。

0

這可能比簡單地禁用Windows防火牆添加規則使用特定端口一個更好的選擇:

防火牆 - >高級設置 - >入站規則 - >新建規則。

相關問題