Sending FaultMessage object of ESB toolkit to dispaly error message on ESB portal

386 Views Asked by At

I am trying to send the dummy fault message from .net class library to ESB management portal using below code. Already consumed WCF service provided by ESB ExceptionHandling Service and created client of it.

                ExceptionHandlingClient clientESB = new ExceptionHandlingClient();
                FaultMessage faultMsg = new FaultMessage();

                faultMsg.Header = new FaultMessageHeader();
                faultMsg.Header.Application = "Exception Handling Service Test";
                faultMsg.Header.Description = "Fault Message Header";
                faultMsg.Header.ErrorType = "Error Type";
                faultMsg.Header.FaultSeverity = 1;
                faultMsg.Header.FaultCode = "Fault Code";
                faultMsg.Header.FailureCategory = "Failure Category";
                faultMsg.Header.FaultDescription = "Fault Description";
                faultMsg.Header.FaultGenerator = "Fault Generator";
                faultMsg.Header.Scope = "Fault Message Scopte";
                faultMsg.Header.ServiceInstanceID = System.Guid.NewGuid().ToString();
                faultMsg.Header.ServiceName = "Exception Service";
                faultMsg.Header.MachineName = System.Environment.MachineName;
                faultMsg.Header.DateTime = System.DateTime.Now.ToString();
                faultMsg.Header.ControlBit = "1";
                faultMsg.Header.MessageID = System.Guid.NewGuid().ToString();
                faultMsg.Header.ActivityIdentity = "Activity Identity ";
                faultMsg.Header.NACK = false;
                 //Use the 'client' variable to call operations on the service.
                clientESB.Open();
                clientESB.SubmitFault(faultMsg);

When above code executes, it sets properties of FaultMessage object successfully. This request when reaches to ALL.Exceptions send port it fails with below error message.

There was a failure executing the send pipeline: "Microsoft.Practices.ESB.ExceptionHandling.Pipelines.ESBFaultProcessor, Microsoft.Practices.ESB.ExceptionHandling.Pipelines, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "ESB BAM Tracker" Send Port: "ALL.Exceptions" URI: "SQL://(local)/EsbExceptionDb/" Reason: Unexpected end of file has occurred. The following elements are not closed: ns0:FaultMessage. Line 20, position 12.

1

There are 1 best solutions below

0
On

If you are sending an Exception Message from a BizTalk Orchestration you can do the following in a Construct Shape that creates a faultMsg of type Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults.FaultMessage

faultMsg = Microsoft.Practices.ESB.ExceptionHandling.ExceptionMgmt.CreateFaultMessage();
faultMsg.FailureCategory = "Failure Category";
faultMsg.FaultCode = "Fault Code";
faultMsg.FaultSeverity = Microsoft.Practices.ESB.ExceptionHandling.FaultSeverity.Error;
faultMsg.FaultDescription = "Fault Description";
faultMsg.Scope = "Fault Message Scope";

Note:

  1. You do not have to set Application or the other settings as they auto-populate in BizTalk
  2. You do not have to consume the web service. You just need a reference in the BizTalk project to the following
    Microsoft.Practices.ESB.Exception.Management
    Microsoft.Practices.ESB.ExceptionHandling
    Microsoft.Practices.ESB.ExceptionHandling.Schemas.Faults