Windows Server 2008上的WCF NetNamedPipeBinding TimeoutException

Windows Server 2008上的WCF NetNamedPipeBinding TimeoutException,wcf,netnamedpipebinding,Wcf,Netnamedpipebinding,我对WCF NetNamedPipeBinding有问题。当我在WindowsXP机器上通过VisualStudio2008运行服务器和客户端代码时,一切正常。但是,当我将服务器部署为Windows服务并在Windows server 2008中安装客户端应用程序时,每当我尝试使用任何契约方法时,客户端就会出现TimeoutException。似乎我可以成功地创建并打开客户端,但无法调用任何方法 服务初始化代码: Uri baseAddress = new Uri("http://localho

我对WCF NetNamedPipeBinding有问题。当我在WindowsXP机器上通过VisualStudio2008运行服务器和客户端代码时,一切正常。但是,当我将服务器部署为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();
客户端初始化代码:

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,我就无法调用任何服务方法。

在尝试了各种绑定并回到基础知识之后,我注意到示例程序可以工作,但我的程序无法工作,除非我使用Visual Studio进行调试。我当时决定,这一定是我自己的代码在起作用。为了简化调试,我关闭了绑定中的所有安全性

我开始注释我服务的OnStart方法中的大部分语句,以确定可能发生的情况。我注释掉了除初始化ServiceHost的代码之外的所有内容。神奇的是,我的客户现在可以成功地与服务进行通信。然后,我开始取消OnStart方法中每一行代码的注释,直到我的客户端突然再次给我一个TimeoutException

我的服务类称为“MyAPI”,实现了契约“IMyAPI”。除了使用“MyAPI”类作为WCF服务外,我还在我的服务内部使用“MyAPI”类的一个实例来做各种事情(“内部”方法)。在OnStart方法中,我首先创建了“MyAPI”类的实例,然后创建了ServiceHost:

MyAPI API = new MyAPI();

ServiceHost service = new ServiceHost(typeof(MyAPI));
我没有收到任何错误或异常,所以看起来一切正常,但实际上我无法使用客户端连接到服务。我一改变上述陈述的顺序,客户就重新开始工作:

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

MyAPI API = new MyAPI();

我不知道为什么会发生这种情况,我所知道的是我可以在内部使用我的API,并将其作为服务使用,而不会出现任何客户端连接问题。也许有人会解释这背后的原因,或者我的代码设计不正确。

好吧,所以我的应用程序不能使用任何绑定类型。相反,我通过创建一个全新的项目来测试netTcpBinding,该项目使用一个全新的服务,该服务只有一个方法:Add(intn1,intn2)。我使用installutil.exe在目标2008服务器上手动安装了该服务,并在我的客户端上进行了服务引用更新,然后运行该程序,没有出现任何问题。我试图将相同的配置复制到不想工作的原始服务中,但仍然无法工作。。。把头发扯下来!