How to Handle Typed Fault Contracts in Orchestrations
This topic describes how to handle typed fault contracts when consuming WCF services from within orchestrations. To handle typed fault exceptions in orchestrations, the WCF services that you are consuming must have the FaultContractAttribute applied to the service operations; therefore, the faults can be thrown by using FaultException<T> where T can be any valid data contract or serializable type from the WCF services.
Procedures
To handle typed fault contracts in orchestrations
In your Microsoft Visual Studio BizTalk project, in Solution Explorer, right-click your project, click Add, and then click Add Generated Items.
In the Add Generated Items - <Project name> dialog box, in the Templates section, select Consume WCF Service, and then click Add.
On the Welcome to the BizTalk WCF Service Consuming Wizard page, click Next.
On the Metadata source page, select Metadata Exchange (MEX) endpoint, and then click Next.
On the Metadata Endpoint page, specify the URL for the running service that provides metadata for download through WS-Metadata Exchange or Http-Get—for example, http://localhost:8005. To get the metadata document from the URL, click Get. If the running service requires a user credential with the basic authentication scheme, click Edit to open the BizTalk WCF Service Consuming Wizard dialog box in which you can supply the user name and password to use when accessing the running service. Click Next.
On the Import WCF Service Metadata Summary page, review your settings. You can click Back to make any changes. Then click Import to create the BizTalk artifacts and types to be used for consuming the WCF service.
On the Completing the BizTalk WCF Service Consuming Wizard page, click Finish.
Suppose that the WCF service that you are consuming throws the following fault exception:
throw new FaultException<MyOperationException>(divideException);
The fault operation on the send port expects a message of type MyOperationException, but the WCF response message contains the whole fault body. Therefore, you need to extract the MyOperationException part from the message by configuring the Inbound BizTalk message body option in the transport properties dialog box. For example,
Select Path -- content located by body path.
Set the Body path expression to the following:
/*[local-name()='Fault']/*[local-name()='Detail']/* | /*[local-name()='DivideResponse']
Select Xml from the Node encoding drop-down list.
In the orchestration, you will need to add a scope and two exception handlers. One exception handler is for the Fault operation, similar to MyOperationException shown in the preceding example; the other exception handler is for catching generic SOAPExceptions.
See Also
How to Throw Fault Exceptions from Orchestrations Published as WCF Services
How to Use the BizTalk WCF Service Consuming Wizard to Consume a WCF Service