7

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

nitefrog
  • 1,760
  • 6
  • 31
  • 59
  • One more thing, sometimes I get this error: The socket connection was aborted. This only happens on a remote machine trying to talk to the host. If client is on the host machine, no problems... Frustrating... – nitefrog Aug 14 '10 at 02:37
  • I smell firewall; can you try `telnet`ing your hosted services from remote pc? Check the firewall of both pcs. Btw, what port are you connecting on? – KMån Aug 14 '10 at 03:13
  • 1
    Please, post an example of your service endpoint configuration. Also, what are the client and server OS and are they on the same domain. What user is the service running as and what user is the client running as. – Franci Penov Aug 14 '10 at 03:32
  • Check out this question. The problem must be un accessible Temp folder. http://stackoverflow.com/q/4119964/1155650 – Rohit Vipin Mathews Dec 19 '12 at 05:49

4 Answers4

3

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" />
…
Community
  • 1
  • 1
Jay
  • 56,361
  • 10
  • 99
  • 123
  • No firewalls. All disabled both host computer and client. Everything is wide open, that is what is confusing me... – nitefrog Aug 14 '10 at 02:48
  • I turned on trace and got this error: A security requirement was not fulfilled during authentication. Required: Sign, negotiated: EncryptAndSign. How can I turn off security??? Help... – nitefrog Aug 14 '10 at 03:18
  • @nitefrog -- added info about disabling security on `NetTcpBinding` – Jay Aug 14 '10 at 04:08
  • "How can I turn off security?" That should set off quite a few sanity alarms around here. – ErikHeemskerk Aug 14 '10 at 04:09
  • @Erik: I'd suggest disabling it as a troubleshooting technique. – John Saunders Aug 14 '10 at 04:19
  • @John: Fair enough, but it appears to me the OP is new to using WCF, so I thought it should be mentioned that it is indeed a troubleshooting technique and not intended for production. – ErikHeemskerk Aug 14 '10 at 04:24
  • @ErikHeemskerk I am just trying to figure out why it is not working. Taking it one step at a time, then adding security back in. – nitefrog Aug 16 '10 at 19:14
  • Still does not work. I added, none, searched the web, and everything seems correct, but it will not work from a remote machine. – nitefrog Aug 16 '10 at 19:15
1

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

John Conde
  • 217,595
  • 99
  • 455
  • 496
S Spencer
  • 11
  • 1
0

On server side I did this and it works:

var tcpServiceUri = new UriBuilder
            {
                Scheme = Uri.UriSchemeNetTcp,
                Host = LocalIPAddress(),//@"127.0.0.1", //IpAddress,
                Port = int.Parse(_port), //BaseTcpPort,
                Path = @"/SomeService",
            };
_host = new ServiceHost(typeof(SomeService), tcpServiceUri.Uri);

public string LocalIPAddress()
{
    IPHostEntry host;
    string localIP = "";
    host = Dns.GetHostEntry(Dns.GetHostName());
    foreach (IPAddress ip in host.AddressList)
    {
        if (ip.AddressFamily == AddressFamily.InterNetwork)
        {
            localIP = ip.ToString();
            break;
        }
    }
    return localIP;
 }
Denis
  • 833
  • 3
  • 12
  • 22
0

Is the WCF service actively listening on that port? You should be able to tell by running from the cmd line:

netstat -a -n -p TCP

It should show that a process is listening on 192.168.1.75:8523

If it does, then have you tried enabling WCF trace logging? To enable that, you would add something like this to your app.config:

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
            <listeners>
                <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "C:\MyApp.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

Then attempt your connection and see if "C:\MyApp.svclog" was created, and if it shows any errors. If you have VisualStudio installed on the given machine, then the ".svclog" file should be able to be opened by just double-clicking it.


EDIT: Sorry, I missed in the comments above that you had already enabled trace logging. At least you know WCF is getting the oncoming message. I've never seen your particular error before though, sorry.

CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138