WCF No connection could be made because the target machine actively refused
Asked Answered
D

6

6

I just implemented a simple WCF server using net.tcp.

First, I use 127.0.0.1 as server address and client able to connect the WCF service.

Everything is Ok. But when I try to use the internal IP 192.x.x.x I get an error:

No connection could be made because the target machine actively refused it

Any idea what may cause this?

Best Wishes

PS: I disabled auth on WCF. Even turn off firewall all...Not worked...

Dudleyduds answered 12/5, 2011 at 15:22 Comment(1)
Can you please share exception stack?Undershrub
C
8

Do you use 192.x.x.x on both client and server? I remember seeing an issue a while back in which for TCP the client and server names needed to match (something related to one of the message properties), so if you define the service with "localhost" and the client with <machine name> there would be a problem.

Clutch answered 12/5, 2011 at 18:19 Comment(2)
Yes... You are right. Local Ip representation should match at both side... ThanksDudleyduds
Did you mean "if you define the service with 'localhost' and the client with 192.x.x.x" ?Recurved
H
9

Well, I got this error message when I forgot to install necessary components. see link Configuring WCF Service with netTcpBinding

(summary of steps)...

  • Go to "Programs and Features" (usually in control panel)
  • Go to "Turn Windows features on or off"
  • (assuming VS2012) Go to ".NET Framework 4.5 Advanced Services"->"WCF Services"
  • Enable "TCP Activation"
Halfhardy answered 18/8, 2014 at 18:54 Comment(2)
hi @Halfhardy : I have done all setting on my staging server as told by you but still i am getting same error can you please guide me on this ??Lebrun
@TheProgrammer - verify firewall restrictions on your staging server. Verify previous answers by carlosfigueira, PeterX, and Moby Stunt Double. Verify URL including port. Also, try to connect to the service using tools like Fiddler to verify WCF service is available.Halfhardy
C
8

Do you use 192.x.x.x on both client and server? I remember seeing an issue a while back in which for TCP the client and server names needed to match (something related to one of the message properties), so if you define the service with "localhost" and the client with <machine name> there would be a problem.

Clutch answered 12/5, 2011 at 18:19 Comment(2)
Yes... You are right. Local Ip representation should match at both side... ThanksDudleyduds
Did you mean "if you define the service with 'localhost' and the client with 192.x.x.x" ?Recurved
V
5

The physical client and service addresses can differ if the logical address is the same and the server endpoint has been configured with a "listenUri" and the client behaviour is configured to use a <clientVia> address. In our case, this is required in for our proxy/firewall configuration. In effect, the client calls the firewall and the server listens locally for a forwarded request.

For an IIS-hosted service, check the following:

  1. The Application pool is started and looks correct (.NET 4 etc/security)
  2. For NET.TCP, ensure the "Allowed Protocols" in the Web Site/Application (via advanced settings) are configured correctly: e.g. http,net.tcp

For a non-IIS hosted service, you may need to configure a Namespace Reservation (URLACL). http://msdn.microsoft.com/en-us/library/ms733768.aspx

Also ensure the appropriate Windows Services are running, e.g. Net.Tcp listener.

Verdaverdant answered 30/5, 2012 at 3:53 Comment(2)
"Also ensure the appropriate Windows Services are running, e.g. Net.Tcp listener." If I had any hair left it would have been torn out by now. Thank you for putting me out of my misery!Anthropophagy
The "Allowed Protocols" fixed my problem, thank you.Cod
T
1

If you're running from within visual studio in debug mode, ensure your solution port numbers match. I have seen several instances where I had Properties>Web>Auto-Assign Port - selected and the endpoint from, in this case my silverlight app, didn't match the port auto generated. I usually change the port to 1318 in my .web.

Turenne answered 12/2, 2013 at 15:48 Comment(0)
H
1

Today I found out that this error will also show up if you have a circular reference in your WCF Service Class. I had a method that was calling itself infinitely and causing this error message, which led me here.

So if none of the other suggestions work, check your code to see if you're doing any recursive functionality and make sure you're not caught in an infinite loop.

Hostetler answered 29/5, 2018 at 21:33 Comment(0)
S
1

I resolved this issue by either commenting this setting in the application configuration:

<defaultProxy>
      <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
    </defaultProxy>

or, running Fiddler which would take the WCF call at 127.0.0.1 and then forward it.

The complete scenario is, I encountered the same issue with WCF calls made to one of the service. The calls would fail with top level error message "There was no endpoint listening at http://LinuxIP:Port/...", and service trace viewer log showing inner exception to be "No connection could be made because the target machine actively refused it 127.0.0.1:8888 ".

The reason was that I had put this configuration in my application to capture the outgoing traffic in Fiddler. If this configuration is in place then the Fiddler needs to be running for the WCF calls to make it to the intended destination. If Fiddler is not running this error will be there. Comment this setting in such scenarios, and the WCF call will go to the destination.

Spit answered 23/1, 2020 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.