Search code examples
c#c#-3.0wcfwcf-binding

How do you configure a WCF service for clients running on networked machines?


I’ve just created a WCF service/client and it all works fine when running on the same machine. But can’t figure out how to configure it to run on different machines. Do you know how?

At the moment the URI is set to http://localHost:8000......

But I think I want something like net.tcp://MyServer:8000…..

Any ideas would be great. Thanks.


Solution

  • From what it sounds like, you have both the service and client in the same executable. While this can be done, when you want them on separate machines you need to have an executable/host for the service (either self hosted, or in IIS) and an executable for the client. Each will need to be properly configured with the address, binding, and contract in the appropriate configuration section for it. So on the server you'd have something like this:

    <configuration>
        <system.serviceModel>
            <services>
                <service name="YourService">
                    <endpoint address="http://MyServer:8000/..."
                              binding="BasicHttpBinding"
                              contract="Your.IContract" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>
    

    And on the client you'd have this:

    <configuration>
        <system.serviceModel>
            <client>
                <endpoint address="http://MyServer:8000/..."
                          binding="BasicHttpBinding"
                          contract="Your.IContract"
                          name="ClientEndpoint" />
            </client>
        </system.serviceModel>
    </configuration>
    

    The main thing is to make sure that the client and server can communicate with each other over the specified port and protocol (primarily making sure a firewall isn't blocking communication). The other thing to be aware of is changing your binding protocol may impact other aspects of your service (security is a big one, but also what you can and cannot do with the service).