Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Windows Service. Can connect locally, but not remotely

Tags:

c#

wcf

wcf-client

I spent two days trying to figure this out and I am stumped. I have a WCF servers running as a service on Windows. A client can connect to it on the same machine, but as soon as I move try to connect to the service from another machine I cant.

So if the client and host are on the same machine, no problems. If the Host and Client are on separate machines I get exceptions errors.

Here is the weird part, I can use the svcutil to generate the app config and proxy.cs files from a remote machine, but as soon as I call the function it spits errors.

Could not connect to net.tcp://ipaddress:port/Service1. TCP Error code 10061. NO connection could be made because the target machine actively refused it.

If I call it from the same machine Host / Client no errors.

Any ideas?

Updated:

Here is the service end point settings.

<system.serviceModel>
    <services>
        <service behaviorConfiguration="Service1Behavior" name="WcfServiceLibrary1.Service1">
            <endpoint address="net.tcp://192.168.1.75:8523/Service1" binding="netTcpBinding"
                contract="WcfServiceLibrary1.IService1" />
            <endpoint address="net.tcp://192.168.1.75:8523/mex" binding="mexTcpBinding"
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://192.168.1.75:8523/" />
                </baseAddresses>
            </host>
        </service>
    </services>
    <bindings>
        <netTcpBinding>
            <binding name = "TcpBindingConfiguration">
                <security mode="None"/>
            </binding>
        </netTcpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Service1Behavior">
                <serviceMetadata />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

I have tried everything.

Any ideas?

Again is the client and host are on the same machine everything is fine, as soon as I put the client on a different computer, no dice...

I have never had this much headache with network programming back in the day...

Thanks

like image 665
nitefrog Avatar asked Aug 14 '10 02:08

nitefrog


2 Answers

If Windows Firewall is enabled on the host machine, try disabling it (you can get there through Control Panel). If it works then, you've found the culprit. You'll need to add an exception for your service in the firewall configuration and reenable it.

Same holds if you are using any other 3rd party firewall software, as is often bundled with antivirus software.

edit:

To set no security over TCP, you can use the constructor in code:

var binding = new NetTcpBinding(SecurityMode.None);

or you can do it in the configuration XML:

<netTcpBinding>
    <binding name="myTcpBinding">
        <security mode="None" />
…
like image 54
Jay Avatar answered Sep 29 '22 11:09

Jay


I was having the same problem "...everything OK if the client and host are on the same machine, but if the Host and Client are on separate machines I get exceptions errors".

This is what solved the problem for me: My internet connection settings used a proxy server. I changed the IE options for the LAN settings to Bypass proxy server for local addresses and Do not use proxy server for addresses beginning with: http:\\host-ip-here

like image 35
S Spencer Avatar answered Sep 29 '22 13:09

S Spencer