gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:41:58 26 4
gpt4 key购买 nike

我如何添加 IncludeExceptionDetailInFaults = true;到下面的代码。我需要获取 Web 服务抛出的 FaultException 的详细信息。目前我没有得到任何细节。看起来我唯一回来的是 .有什么想法吗?

C#代码

CustomBinding Binding = new CustomBinding(BINDING_NAME);

EndpointAddress EndPoint = new EndpointAddress(WsEndpoint);

// Trust all certificates
ServicePointManager.ServerCertificateValidationCallback = ((Sender, certificate, chain, sslPolicyErrors) => true);

_WsProxy = new MyDataSoapClient(Binding, EndPoint);

//_WsProxy.Endpoint.Behaviors.Add(????);

_WsProxy.ChannelFactory.Credentials.UserName.UserName = "username";
_WsProxy.ChannelFactory.Credentials.UserName.Password = "pwd";

最佳答案

我认为您必须添加一个 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();

关于c# - 如何将 WCF IncludeExceptionDetailInFaults 添加到端点行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4259371/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com