views:

79

answers:

1

Hi

I require a Windows Service to make WCF calls to a service hosted in a WinForms application.

Unfortunately when attempting the call the Windows Service fails to discover the Endpoint.

I have tried changing the Log On properties for the Windows Service to allow interaction with the desktop, however this did not help.

I have used the exact same hosting code (as used by the WinForms app) in a Console application and the Windows Service finds the Endpoint no problem.

Any help would be much appreciated...

Code to host service in WinForms app.

_myServiceHost = new ServiceHost(typeof(MyService); 
_myServiceHost.AddServiceEndpoint 
( 
    typeof (IMyService), 
    new NetNamedPipeBinding(), 
    @"net.pipe://localhost/MyService"
); 
_myServiceHost.Open(); 

Code from the client proxy...

_serviceFactory = new ChannelFactory<IMyService> 
( 
    new NetNamedPipeBinding(), 
    "net.pipe://localhost/MyService" 
); 
... 
IMyService clientProxy = _serviceFactory.CreateChannel(); 
clientProxy.SomeMethod();

This problem does appear to be to do with the security context in which windows services run that is preventing the Endpoint hosted by the WinForms app from being visible to the service but not vica versa.

UPDATE:

I tried changing the binding from NetNamedPipeBinding to NetTcpBinding and it seems to work fine with this type of binding.

+1  A: 

Are you sure that you have the app.config in its place and you have opened the service host? The issue must be in that. And windows service has no role here, check it with wcftestclient and also try to view the wsdl (if enabled) in web browser.

But mainly I believe you have not opened the host :

ServiceHost host = new ServiceHost(....);
host.Open(); // check is it successfully called
Incognito
The service is definitely being hosted. I have tried both console and winforms apps to test the service host (exact same code). I alsohave a test application using the same client proxy that works fine, it appears to only be Windows Service -> Winforms that fails.Windows Service -> Console app (OK)Windows Service -> WinForms app (Fail)WinForm App -> WinForm app (OK)All three configurations are using the same client proxy code and the same service hosting code.There is currently no app.config, the bindings are purely in code for now.
M. Williamson
It looks very strange. Can we see any code ?
Incognito
@M. Williamson As also said please update the question and put code there.
Incognito