我如何添加IncludeExceptionDetailInFaults = true;到下面的代码。我需要获取Web服务抛出的FaultException的详细信息。目前我没有收到任何细节。看起来我唯一能回来的就是。任何想法?
c#code
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";
答案 0 :(得分:5)
我认为你必须添加一个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();