Windows Server 2008 上的 WCF NetNamedPipeBinding TimeoutException
我遇到 WCF NetNamedPipeBinding 问题。当我在 Windows XP 计算机上通过 Visual Studio 2008 运行服务器和客户端代码时,一切正常。但是,一旦我将服务器部署为 Windows 服务并在 Windows Server 2008 中安装客户端应用程序,每当我尝试使用任何合约方法时,我都会在客户端收到 TimeoutException。看来我可以成功创建客户端并打开它,但无法调用任何方法。
服务初始化代码:
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();
客户端初始化代码:
string address = "net.pipe://localhost/xNet/xNetService";
NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
_serviceClient = new ServiceAPIClient(binding, new EndpointAddress(address));
_serviceClient.Open();
Windows 服务作为“本地系统帐户”运行。我不知道问题是什么。我不知道是否是安全帐户问题,或者命名管道是否打开?我认为既然我可以成功创建并打开客户端,那么它看起来至少找到了命名管道。我只是无法在没有 TimeoutException 的情况下调用任何服务方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在尝试了各种绑定并回到基础知识后,我注意到示例程序可以工作,但我的程序不能工作,除非我使用 Visual Studio 进行调试。那时我决定这一定是我自己的代码出了问题。为了简化调试,我关闭了绑定中的所有安全性。
我开始注释掉服务的 OnStart 方法中的大部分语句,以确定可能发生的情况。除了初始化 ServiceHost 的代码之外,我注释掉了所有内容。神奇的是,我的客户现在可以成功地与该服务进行通信。然后,我开始取消 OnStart 方法中每一行代码的注释,直到我的客户突然再次开始给我一个 TimeoutException。
我的服务类(例如“MyAPI”)实现了契约“IMyAPI”。除了使用“MyAPI”类作为 WCF 服务之外,我还在服务内部使用“MyAPI”类的实例来执行各种操作(“内部”方法)。在我的 OnStart 方法中,我首先创建了“MyAPI”类的实例,然后创建了 ServiceHost:
我没有收到任何错误或异常,所以看起来一切都很好,但实际上我无法使用客户端连接到服务。一旦我更改了上述语句的顺序,客户端就再次开始工作:
我不确定为什么会发生这种情况,我所知道的是我可以在内部使用我的 API 并将其作为服务使用,而不会出现任何客户端连接问题。也许有人会提供一些关于这背后的原因的信息,或者也许我的代码设计不正确。
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:
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:
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.