我托管一个来自表单应用程序的Net.Pipe WCF服务,该应用程序运行在服务器上,主要用于内部计算。为了改进这一点,我的任务是围绕这个服务创建一个Rest,这样它就可以从服务器外部访问。我设法轻松地连接到此服务,但一旦我将它放到活动服务器上,我的rest shell就无法再连接,我试着调试它,但是记录的主要错误消息是:
服务器由于内部错误无法处理请求。有关此错误的更多信息,请打开服务器上的IncludeExceptionDetailInFaults ( ServiceBehaviorAttribute或serviceDebug配置行为),以便将异常信息发回客户端,或根据Microsoft .NET Framework文档启动跟踪并检查服务器跟踪日志。
问题是,我通过代码连接到这个服务,我无法知道如何转换连接到服务主机的方式,这样我就可以添加服务行为,或者将行为添加到我的通道工厂中。
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服务。(我仍在研究第二个方案)
发布于 2020-03-03 14:32:46
我发现了问题,我尝试将行为添加到rest (连接端),而应该将其添加到承载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();幸运的是,我现在收到了一条实际工作的错误消息,结果发现我丢失了一个特定的dll,该dll在部署到服务器期间没有正确构建。
https://stackoverflow.com/questions/60508949
复制相似问题