The Exception Handling web service

This service was already introduced in the Chapter 3, ESB Exception Handling, dedicated to the exception management in the ESB Toolkit.

In order to submit a fault into the ESB so it's handled by the standard ESB faults processing logic we might have in place in our ESB, we just need to instantiate the FaultMessage class defined in the service contract, fill its properties, and use it as an input for the SubmitFault operation of the service.

The properties on that fault message are the same as the ones we already described in the Chapter 3, ESB Exception Handling:

Ex.ExceptionHandling handleException = new ExceptionHandlingService.SubmitFault.ExceptionHandling();
                handleException.Credentials = System.Net.CredentialCache.DefaultCredentials;
               
                Ex.FaultMessage faultMsg = new Ex.FaultMessage();
                faultMsg.Header = new Ex.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 Scope";
                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;


                Ex.ExceptionHandling exceptionHandler = new Ex.ExceptionHandling();
                faultMsg.ExceptionObject = new Ex.FaultMessageExceptionObject();
                faultMsg.ExceptionObject.Message = "Exception Messge";
                faultMsg.ExceptionObject.Source = "Exception Source";
                faultMsg.ExceptionObject.Type = "Exception Type";
                faultMsg.ExceptionObject.TargetSite = "Exception Target";
                faultMsg.ExceptionObject.StackTrace = "Exception Stack Trace";
                faultMsg.ExceptionObject.InnerExceptionMessage = "Inner Exception Message";

                List<Ex.ArrayOfFaultMessageMessageContextPropertyContextProperty> contexts = new List<Ex.ArrayOfFaultMessageMessageContextPropertyContextProperty>()
                {
                    new Ex.ArrayOfFaultMessageMessageContextPropertyContextProperty{Name = "Context Name1", Type = "Context Type1", Value = "Context Value1"},
                    new Ex.ArrayOfFaultMessageMessageContextPropertyContextProperty{Name = "Context Name2", Type = "Context Type2", Value = "Context Value2"}
                };



                Ex.ArrayOfFaultMessageMessageMessageMessageData messagedata = new Ex.ArrayOfFaultMessageMessageMessageMessageData();
                XmlDocument xmldoc = new XmlDocument();
                // XmlDocumentFragment fragIn = xmldoc.CreateDocumentFragment();
                xmldoc.LoadXml("<Order><customerName>Microsoft</customerName><ID>10</ID><requestType>10</requestType></Order>");
                XmlNode[] anyField = new System.Xml.XmlNode[1];
                anyField[0] = (XmlNode)xmldoc;
                messagedata.Any = anyField;



                List<Ex.ArrayOfFaultMessageMessageMessage> messages = new List<Ex.ArrayOfFaultMessageMessageMessage>() 
                {
                    new Ex.ArrayOfFaultMessageMessageMessage{ContentType = "text/xml",InterchangeID = "InterchangeID1",MessageID = "MessageID1",MessageName = "MessageName1",MessageType = "MessageType1",MessageContext = contexts.ToArray(),MessageData = messagedata},
                    new Ex.ArrayOfFaultMessageMessageMessage{ContentType = "text/xml",InterchangeID = "InterchangeID2",MessageID = "MessageID2",MessageName = "MessageName2",MessageType = "MessageType2",MessageContext = contexts.ToArray(),MessageData = messagedata}
                };                      


                faultMsg.Messages = messages.ToArray();
                handleException.SubmitFault(faultMsg);

This service is also available in both ASMX and WCF flavors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.246.148