WCF: FaultContract (typeof (ExceptionDetail)) release

I applied the [FaultContract(typeof(ExceptionDetail))] attribute to my operation contract. When I try to add a service to the client application, I get this error - "Custom tool error: Failed to generate code for the service reference 'ServiceReference1'. Please check other error and warning messages for details."

But when I comment on the FaultContract attribute, I can add a link to the wcf service in my client application.

+4
source share
4 answers

The point of presence of FaultContracts allows you to first send back SOAP errors from a service that will not break the communication channel between the server and the client (error handling, such as .NET exceptions, is elegant and interoperable) and secondly, using FaultContracts, your server than throw typed errors ( FaultException<T> ), and your client will be able to catch them.

If you want or need to be truly compatible, you need to:

  • defines all FaultContract types as classes decorated with the [DataContract] attribute
  • catch all .NET exceptions on the server (using, for example, the IErrorHandler interface) and turn them into compatible SOAP errors

If you control both ends of the wire, and both ends are .NET, then you can simplify this by one step: on the server, handle all .NET exceptions and turn them into, for example. FaultException<ArgumentOutOfRangeException> , i.e. create an "error (regardless of the .NET exception)", and then catch the introduced FaultException on the client and handle them:

 [FaultContract(typeof(ArgumentOutOfRangeException)] [OperationContract] public void CallService(.......) 

and then in your implementation, use this:

 try { clientProxy.CallService(); } catch(FaultException<ArgumentOutOfRangeException> ex) { // handle the most specific exception first } catch(FaultException ex) { // handle all other, unspecific server faults } catch(CommunicationException ex) { // handle all other, client-proxy related WCF errors } catch(Exception ex) { // handle anything else.... } 
+9
source

Remove this FaultContract and instead configure includeExceptionDetailInFaults :

  <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="Behavior"> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> 
+2
source

To view the activity trace, use the Utility Tracer tool from http://msdn.microsoft.com/en-us/library/ms732023.aspx .

0
source

I had the same problem a few minutes ago. This was due to the lack of a default constructor. Also remember that all properties must have public get / set accessors.

0
source

Source: https://habr.com/ru/post/1304465/


All Articles