1

I have a problem with WCF NetNamedPipeBinding. When I run my server and client code through Visual Studio 2008 on a Windows XP machine everything works fine. But as soon as I deploy my server as a Windows Service and install my client app in Windows Server 2008 I get a TimeoutException on the client end whenever I try to use any of the contract methods. It seems that I can successfully create the client and open it, but can't call any of the methods.

Service initialisation code:

Uri baseAddress = new Uri("http://localhost:8500/xNet/xNetService");
string address = "net.pipe://localhost/xNet/xNetService";

_xNetAPIServiceHost = new ServiceHost(typeof(xNetService), baseAddress);

NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
_xNetAPIServiceHost.AddServiceEndpoint(typeof(IServiceAPI), binding, address);

// Add a mex endpoint
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.HttpGetUrl = new Uri("http://localhost:8501/xNet/xNetService/mex");
_xNetAPIServiceHost.Description.Behaviors.Add(smb);

_xNetAPIServiceHost.Open();

Client initialisation code:

string address = "net.pipe://localhost/xNet/xNetService";

NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

_serviceClient = new ServiceAPIClient(binding, new EndpointAddress(address));
_serviceClient.Open();

The Windows service runs as "Local System Account". I'm at a loss as to what the problem is. I don't know if it's a security account problem, or if the named pipe is even open? I would assume since I can successfully create and open the client side it would appear it at least found the named pipe. I just can't call any of the service methods without a TimeoutException.

templar112
  • 23
  • 1
  • 4
  • Alright, so my app doesn't work with ANY binding type. Instead I tested netTcpBinding by creating a brand new project, with a brand new service that just has one method: Add(int n1, int n2). I installed the service manually on the target 2008 server using installutil.exe and on my client I did a service reference update and then ran the program with no problems. I tried to copy the same configuration into my original service that doesn't want to work, but it still doesn't work ... *rips hair out*! – templar112 Dec 16 '11 at 09:41

1 Answers1

0

After trying out various bindings and going back to basics I noticed that the sample programs worked, but mine didn't work unless I was using Visual Studio to debug. I decided at that point that it must be something going on with my own code. To simplify debugging I turned off all security in the binding.

I started commenting out most of the statements in my service's OnStart method in order to determine what could be going on. I commented out everything except for the code that initialises the ServiceHost. Magically, my client could now successfully communicate with the service. I then started uncommenting each line of code in the OnStart method until my client suddenly started giving me a TimeoutException again.

My service class, say "MyAPI", implements the contract "IMyAPI". As well as using "MyAPI" class as the WCF service, I was also using an instance of the "MyAPI" class internally in my service to do various things ("internal" methods). In my OnStart method I first created an instance of the "MyAPI" class and then created the ServiceHost:

MyAPI API = new MyAPI();

ServiceHost service = new ServiceHost(typeof(MyAPI));

I was not getting any errors or exceptions, so it appeared everything is fine, but really I couldn't connect to the service using a client. As soon as I changed the order of the above statements, the client started working again:

ServiceHost service = new ServiceHost(typeof(MyAPI));

MyAPI API = new MyAPI();

I'm not sure WHY this is occuring, all I know is that I can use my API internally and as a service without any client connection issues. Maybe someone out there will provide some light on the reasons behind this, or maybe my code is not properly designed.

templar112
  • 23
  • 1
  • 4