2010-11-23 33 views
5

如何添加IncludeExceptionDetailInFaults = true;到下面的代碼。我需要獲取Web服務拋出的FaultException的詳細信息。目前我沒有得到任何細節。它看起來像我回來的唯一的事情是。有任何想法嗎?如何將WCF IncludeExceptionDetailInFaults添加到端點行爲?

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"; 
+0

你沒有 - 這只是一個服務器端的ServiceBehavior,真的。客戶應該包括哪些異常詳細信息?這隻在服務器端 – 2010-11-23 19:16:42

+0

上有意義,您必須通知服務器在拋出ExceptionFault時在消息中包含異常詳細信息。它已經在服務器上配置,只有在詢問時才返回ExceptionDetails。 – Anthony 2010-11-26 15:54:25

回答

4

我認爲你必須添加一個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(); 
相關問題