0

我正在从表单应用程序托管 Net.Pipe WCF 服务,该服务在服务器上运行,主要用于内部计算。为了改进这一点,我的任务是围绕该服务创建一个 Rest shell,以便可以从服务器外部访问它。我设法轻松地连接到该服务,但是一旦将其放在实时服务器上,我的 rest shell 就无法再连接,我尝试对此进行调试,但记录的主要错误消息是:

由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上打开 IncludeExceptionDetailInFaults(来自 ServiceBehaviorAttribute 或来自 serviceDebug 配置行为)以便将异常信息发送回客户端,或者根据 Microsoft .NET Framework SDK 文档打开跟踪并检查服务器跟踪日志。

问题是我从代码连接到此服务,但我无法弄清楚如何转换我连接到服务主机的方式,以便我可以添加服务行为或将行为添加到我的通道工厂。

NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
ServiceDebugBehavior behavior = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true };
EndpointAddress ep = new EndpointAddress("net.pipe://localhost/IPCService");
ChannelFactoryfactory = new ChannelFactory<RadanWrapper.IRadanContract>(binding);

// This line doesn't work
factory.Endpoint.EndpointBehaviors.Add(behavior as IServiceBehavior);
_channel = factory.CreateChannel(ep);

所以问题是:如何将行为连接到通道工厂,或者,如何通过服务主机连接到这个 net.pipe 服务。(我仍在研究第二种选择)

4

1 回答 1

0

I found the problem, I tried adding the behavior to the rest shell (connecting end), while it should have been added to the forms application (Hosting end) that was hosting the net.Pipe WCF

ServiceHost serviceHost = new ServiceHost(typeof(IPCService));
NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);

// Create new behavior, remove any existing behaviors and add this new one.
var behavior = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true };
serviceHost.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
serviceHost.Description.Behaviors.Add(behavior);
serviceHost.AddServiceEndpoint(typeof(IPCService), binding, "net.pipe://localhost/IPCService");
serviceHost.Open();

Good thing I now got an actually working error message, turns out I was missing a specific dll that didn't get build correctly during deployment to the server.

于 2020-03-03T14:32:46.490 回答