The example project returns an xml containing the exception message and details. It follows the custom schema:
This will be the sample output error on the Console application consuming the web service:
The project includes an orchestration that receives an input file conforming to activate a package. I will discuss on how to make a custom fault message (TransmissionError.xsd as its message type) on Exception Handling having System.Exception as its object type within the scope. This is the overview of the orchestration:
You will notice that a decision shape exists after the scope. This is to avoid the following errors that may occur:
- must receive before sending a fault message on an implemented port
- must receive before sending a message whose message type corresponds to a request response operation on an implemented port.
The decision shape makes sure that only one action – with transmission error (fault message) or none (response) – will be sent to the request-response port.
First, set the transaction type of your scope to None. Then, add a new Exception Handler and set its object type to System.Exception and its Object Name to “ex”:
Before adding an exception, make sure that the logic within the scope is tested to run correctly. This is the sample exception created:
The expression that is created (Successful = False) serves as Flag to indicate that the activation of package was unsuccessful. The first Construct Message shape receives “xdoc”(created from scope > message of type System.Xml.XmlDocument ). Inside the Message Assignment expression editor, type the following:
xdoc = new System.Xml.XmlDocument(); xdoc.LoadXml("
Paste the generated instance of the TransmissionError schema: ex. =<ns0:TransmissionError xmlns:ns0='http://...Internal.TransmissionError'><Message>Message_0</Message><ExceptionDetails>ExceptionDetails_0</ExceptionDetails></ns0:TransmissionError>");
The second Construct Message shape constructs the TransmissionError message of type TransmissionError.xsd above. Type the following on its message assignment:
TransmissionError = xdoc; TransmissionError.Message = ex.Message; TransmissionError.ExceptionDetails = ex.ToString();
Notice the example from Console Application output error above: ex.Message displays “DeliveryFailureException”, ExceptionDetails receives the details from ex.ToString(); After the scope, the decision shape looks into the Flag whether an exception occurs. So if the the transaction encounters a transmission error, then it would go to the exception handler that sets the Flag to false and constructs the exception to TransmissionError message.
Also, when you encounter the following error upon testing your Web Service:
The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
This is because you need to set the includeExceptionDetailInFaults to “true” inside the Web.config usually located in C:\inetpub\wwwroot\NameOfWebsite. 🙂