简体   繁体   English

在 channelfactory WCF Net.Pipe 上设置 ServiceBehavior

[英]Set ServiceBehavior on channelfactory WCF Net.Pipe

I am hosting a Net.Pipe WCF service from a forms application, which runs on a server for mostly internal calculations.我从表单应用程序托管 Net.Pipe WCF 服务,该服务在服务器上运行,主要用于内部计算。 To improve on this I was tasked with creating a Rest shell around this service so it becomes reachable from outside of the server.为了改进这一点,我的任务是围绕该服务创建一个 Rest shell,以便它可以从服务器外部访问。 I managed to connect to this service with ease, but as soon as I drop it on the live server My rest shell can no longer connect, I tried debugging this, but the main error message that gets logged is:我设法轻松地连接到此服务,但是一旦我将它放到实时服务器上,我的 rest shell 就无法再连接,我尝试调试它,但记录的主要错误消息是:

The server was unable to process the request due to an internal error.由于内部错误,服务器无法处理请求。 For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the serviceDebug configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.有关错误的详细信息,请在服务器上打开 IncludeExceptionDetailInFaults(从 ServiceBehaviorAttribute 或从 serviceDebug 配置行为)以将异常信息发送回客户端,或者根据 Microsoft .NET Framework SDK 文档打开跟踪并检查服务器跟踪日志。

Thing is that I connect to this service from code and I cannot figure out how to either convert the way I connect to a service host so I can add the Service behavior or add the behavior to my channel factory.问题是我从代码连接到这个服务,我无法弄清楚如何转换我连接到服务主机的方式,以便我可以添加服务行为或将行为添加到我的通道工厂。

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);

So the question is either: How do I connect the behavior to the channel factory, or alternatively, how can I connect to this net.pipe service through service host.所以问题是:我如何将行为连接到通道工厂,或者,我如何通过服务主机连接到这个 net.pipe 服务。 (I am still looking into the second options) (我还在研究第二个选项)

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我发现了问题,我尝试将行为添加到其余 shell(连接端),而它应该已添加到托管 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.好在我现在收到了一条实际工作的错误消息,结果我丢失了一个在部署到服务器期间没有正确构建的特定 dll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM