Thursday, October 27

Create a Soap Exception Catching Process from an Orchestration Request-Response Port using the ESB Portal

  1. In your orchestration, add a reference to Microsoft.Practices.ESB.ExceptionHandling and Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults (Open your project, Richt-Click on References > Add Reference > .Net and double-click on Microsoft.Practices.ESB.ExceptionHandling and use the same process for Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults )
  2. In your orchestration, create a Scope of Transaction Type ‘None’
  3. Add your operations for which you wish to catch the exception in this scope (make sure any messages to be used in the exception catching block are created outside this scope, although the message can also be created within the scope if necessary, in which case extra steps will need to be taken to initialize the message)
  4. On the Request-Response port from which you wish to capture the soap exception, Right-click on the port Operation and create a new orchestration Message called ‘Soapfaultmsg’ of Type ‘BTS.soap_envelope_1__1.Fault’. (you can find this type in Referenced Schemas à Microsoft.BizTalk.globalPropertySchemas)
  5. Create an orchestration Message called ‘msgESBFault’ of Type Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults.FaultMessage (Schemas >Select from referenced assemblies)
  6. Create orchestration Message called ‘msgSoapFault’ of type System.Xml.XmlDocument
  7. Right-click on the scope and add a new Exception Handler called ‘CatchSoapException’
  8. In the Exception properties, Enter ‘SoapExceptionobjmsg’ as the Exception Object Name (or any other descriptive name you choose)
  9. In the Exception properties, Select ‘<Your Request-Response Port>.<Your Request-Response Port Operation>. Soapfaultmsg’ as the Exception Object Type
  10. In the Exception Handler, add an Expression Shape called ‘WriteTraceEventLog’, Construct Message Shape called ‘ConstructESBFaultmsg’ and a Send Shape called ‘SndESBFaultmsg’. In the construct message shape, add a Message Assignment Shape called ‘AssignESBFaultmsg’
  11. Add a direct Send Port ‘ESBFaultPort’ of Type ‘ESBFaultPortType’ (See steps below)
    • Add a Send Port Shape to the left or right Port Surface in the orchestration designer
    • On the ‘Welcome To The Port Configuratio’n page that opens up in the Port Configuration Wizard, click Next
    • In the Port Properties, enter ‘ESBFaultPort’ as the port name. Click Next
    • On the ‘Select A Port Type’ page, select ‘Create a new Port Type’, in the ‘Port Type Name’ field, enter ‘ESBFaultPortType’, Select ‘One-Way’ as the port Communication Pattern and leave the ‘Access Restrictions’ on the default (Internal). Click Next
    • On the ‘Port Binding’ page, In the ’Port direction of Communication’ drop-down, select ‘I’ll always be sending messages on this port’. In the ‘Port Binding’ drop-down, select ‘Direct’ as the binding method. Leave the default values. Click Next
    • On the ‘Completing the Port Wizard’ page, click Finish
  12. Add ‘Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults.FaultMessage’ as the message type of the direct send port’s Operation (see step 5 above)
  13. In the Message Assignment shape, generate the ESB fault message and add your original message (from the actual scope – see full sample for more information) such as:
    msgSoapFault = SoapExceptionobjmsg;
    // create new fault message msgESBFault=Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.CreateFaultMessage();
    // set fault message properties
    msgESBFault.FaultCode="0001";
    msgESBFault.FaultDescription="SOAP Exception whilst requesting Information from blah-blah system:" + System.Environment.NewLine + "InnerXML is: " + msgSoapFault.InnerXml.ToString();
    msgESBFault.FailureCategory="SOAP Exception whilst requesting Information from wcf service";
    msgESBFault.FaultSeverity=Microsoft.Practices.ESB.ExceptionHandling.FaultSeverity.Severe;
    //Add the fault message to the original message Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.AddMessage(msgESBFault, msgFromOutsideScope);
  14. Connect the send shape ‘SndESBFaultmsg’ to the direct send port ESBFaultPort
  15. In the Expression shape called ‘WriteTraceEventLog’, add the event log entry and debug helper messages such as:  System.Diagnostics.Trace.WriteLine("SOAP Exception whilst requesting Information from <The SOAP Port Service> system"); System.Diagnostics.EventLog.WriteEntry("<Your Application Name>", "SOAP Exception whilst requesting Information from <The SOAP Port Service> system");
Note: To use the event log, you must ensure your BizTalk instance user has sufficient permissions to write to the host system's event log, otherwise, omit the 'System.Diagnostics.EventLog.WriteEntry' line

No comments:

Post a Comment