我如何添加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/