简体   繁体   中英

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

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?

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM