6

how do i add IncludeExceptionDetailInFaults = true; to the below code. I need to get the details of the FaultException thrown by the web service. currently i am not getting any details back. It looks like the only thing i get back is the . any ideas?

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";
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Anthony
  • 536
  • 1
  • 8
  • 27
  • Youc an't - this is only a server-side ServiceBehavior, really. What should the client include exception details for?? That only makes sense on the server-side – marc_s Nov 23 '10 at 19:16
  • you have to tell the server to include the exception details in the message when an ExceptionFault is thrown. it is already configured on the server to return ExceptionDetails only when asked for. – Anthony Nov 26 '10 at 15:54

1 Answers1

5

I think you'll have to add a 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();
Urda
  • 5,460
  • 5
  • 34
  • 47
as-cii
  • 12,819
  • 4
  • 41
  • 43
  • I tried that prior to posting it expects IEndpointBehavior The best overloaded method match for 'System.Collections.ObjectModel.Collection.Add(System.ServiceModel.Description.IEndpointBehavior)' has some invalid arguments – Anthony Nov 23 '10 at 18:54
  • Where are you setting this behavior? In client-side? – as-cii Nov 23 '10 at 19:11
  • i thought that can only be used on a Service using the BasicHttpBinding. I am using CustomBinding in my app. i basically used the svcutil to create the namespace and class from the wsdl. then i use the CustomBinding object and the config settings according to what was configured from the svcutil command. any thoughts, can i still use your method? – Anthony Nov 26 '10 at 13:17
  • You can use this methods ONLY in your hosting: with the code I proposed, you just say to server: "hey, show to the clients that are connected why occurred an Exception". So, if I have well understood you're trying to use this kind of thing inside client but you have to set it in server. I shown you how to do it programmatically, but you can also set it in the configuration file, adding in behaviors. – as-cii Nov 26 '10 at 14:32
  • i have no control over the server. i need to set it in the client. it the Exception detail is set in the server already. I have looked all over the place for how to set this in the config for a customBinding but have come up short. everything shows it for a basicHttpBinding. Plus with how the code was set up there it does not use ServiceHost. Sorry i am a beginner when it comes to secure soap messages – Anthony Nov 26 '10 at 15:52