How to set up my WCF service to be able to be accessed by remote clients

筅森魡賤 提交于 2019-12-25 03:49:10

问题


I have a WCF service that is being hosted in a windows service and I can connect to it and consume its services just fine when using the same machine, but when I try to run my client on a remote machine it times out and won't connect. I thought I could just update the app.config file for the client with the IP of the service machine instead of localhost, but that didn't work. Here is the app.config of the client:

<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>

And here is the app.config of the serivice:

<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>

Is there something I need to do on the service side to allow remote connections or am I just no configuring the client correctly?


回答1:


This may seem like a simplistic suggestion, but have you checked the firewall on your server to make sure that it's not blocking communications? I spent three days banging my head on a wall until I noticed that.




回答2:


This seems like you are doing this from home based on your 192 address.

You will need to punch a whole in your router and windows firewall to start. After that if you want to access this out side of your house you should try using DynDNS to fake having a static IP for hosting the service.




回答3:


Are you able to telnet to your service? If it is not a firewall issue, I suspect from the service security. Since it configured to authenticate via windows credential, which requires your service and client to be in the same domain, correct me if I'm wrong.




回答4:


It might be a better option than simply disabling the windows firewall to add a rule for the specific port using:

Firewall -> Advanced Settings -> Inbound Rules -> New Rule.



来源:https://stackoverflow.com/questions/7505126/how-to-set-up-my-wcf-service-to-be-able-to-be-accessed-by-remote-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!