Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将WCF IncludeExceptionDetailInFaults添加到端点行为?_C#_Wcf_Wcf Binding - Fatal编程技术网

C# 如何将WCF IncludeExceptionDetailInFaults添加到端点行为?

C# 如何将WCF IncludeExceptionDetailInFaults添加到端点行为?,c#,wcf,wcf-binding,C#,Wcf,Wcf Binding,如何添加IncludeExceptionDetailInFaults=true;到下面的代码。我需要获得web服务引发的FaultException的详细信息。目前我没有得到任何细节回来。看来我唯一能得到的就是那辆车。有什么想法吗 c#代码 我认为您必须添加一个ServiceDebugBehavior ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:6598/")); host.Add

如何添加IncludeExceptionDetailInFaults=true;到下面的代码。我需要获得web服务引发的FaultException的详细信息。目前我没有得到任何细节回来。看来我唯一能得到的就是那辆车。有什么想法吗

c#代码


我认为您必须添加一个ServiceDebugBehavior

ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:6598/"));
host.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), "MyService");
host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
host.Open();

我在发布之前尝试过,它期望IEndpointBehavior是“System.Collections.ObjectModel.Collection.Add(System.ServiceModel.Description.IEndpointBehavior)”的最佳重载方法匹配项具有一些无效参数。您在哪里设置此行为?在客户端?我认为这只能在使用BasicHttpBinding的服务上使用。我正在我的应用程序中使用CustomBinding。我基本上使用svcutil从wsdl创建名称空间和类。然后根据svcutil命令配置的内容使用CustomBinding对象和配置设置。有什么想法吗,我还能使用你的方法吗?你只能在你的主机中使用这种方法:使用我提出的代码,你只需对服务器说:“嘿,向连接的客户端显示为什么发生异常”。所以,若我已经很好地理解了你们试图在客户端中使用这种东西,但你们必须在服务器中设置它。我向您展示了如何以编程方式进行设置,但您也可以在配置文件中进行设置,添加行为。我无法控制服务器。我需要在客户端设置它。如果已在服务器中设置了异常详细信息,则为空。我已经到处寻找如何在customBinding的配置中设置它,但是没有找到。一切都显示了它的基本特性。加上代码的设置方式,它不使用ServiceHost。很抱歉,在保护soap消息方面,我是一个初学者—实际上,这只是一种服务器端服务行为。客户机应包含哪些异常详细信息??这只有在服务器端才有意义。当抛出ExceptionFault时,您必须告诉服务器在消息中包含异常详细信息。服务器上已将其配置为仅在请求时返回ExceptionDetails。
ServiceHost host = new ServiceHost(typeof(MyService), new Uri("http://localhost:6598/"));
host.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), "MyService");
host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
host.Open();