Windows服务中的WCF客户端

Windows服务中的WCF客户端

问题描述:

使Windows服务作为WCF客户端运行是否有什么特别之处?

我写了以下内容:

-充当WCF ServiceHost的Winforms应用程序

-充当WCF客户端的Winforms应用程序

-充当WCF客户端的Windows服务

WCF东西使用NamedPipe绑定.

当我运行winforms客户端应用程序时,它可以与服务主机应用程序正常通信.如果我使用Windows服务尝试相同的代码,则似乎无法找到服务主机(找不到端点).

WCF的所有内容都驻留在自己的程序集中,以确保我使用相同的Uri和绑定,并且上面列出的所有三个应用程序都使用该程序集.我不知道为什么在winforms客户端应用程序*会*时该服务无法正常工作.

Is there something special about making a Windows service run as a WCF client?

I''ve written the following:

- A Winforms app that acts as a WCF ServiceHost

- A Winforms app that acts as a WCF client

- A Windows service that acts as a WCF client

The WCF stuff uses NamedPipe Binding.

When I run the winforms client app, it communicates with the service host app just fine. If I try the very same code with the Windows service, it doesn''t seem to be able to find the service host (endpoint not found).

All of the WCF stuff lives in its own assembly to make sure I''m using the same Uri and binding, and all three of the apps listed above use that assembly. I have no idea why the service wouldn''t work when the winforms client app *would*.

John,

我相信这是设计使然.由于您的WCF服务是以非管理员用户身份运行的,因此它创建的命名管道终结点将无法在其他会话中运行的应用程序全局访问.

若要进行测试,请以管理员身份显式运行WinForms应用程序(使用以管理员身份运行"选项).现在,您很可能会发现Windows服务WCF客户端可以连接到它.

据我所知,除了选择不同的绑定机制外,没有解决此问题的真正方法.
John,

I believe this is by design. Since your WCF service is running as a non-Admin user, the named pipe endpoint it creates will not be globally accessible by apps running in other sessions.

To test this out, run your WinForms app explicitly as Administrator (using the Run as Administrator option). Now you''ll most likely find that the Windows service WCF client can connect to it.

As far as I know, there''s no real workaround to this issue other than choosing a different binding mechanism.