WCF: Windows service cannot find endpoint when hosted in Winforms application
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 an开发者_JAVA百科d 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.
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
精彩评论