Defining SOAP Web Service Faults
A WSDL file can contain a fault element for an operation and a message attribute that contains the fault message. Accordingly, when designing a SOAP Web service in MapForce, you can add a "Fault" component to your mapping. This will cause the Web service to throw an exception if a certain condition is satisfied.
To insert a Fault component in a mapping, a fault element must be present in the WSDL file.
You can define the failure condition inside the mapping, and you can also set the text of the error message. When the condition is satisfied, the Web service will fail as follows:
•In a live environment (at execution time, after the Web service is deployed to a server), the Web service will fail and return the custom-defined message to the caller.
•In MapForce (at design time), the mapping execution stops, and you can view the message in the Message window.
To add a fault component to a MapForce mapping:
1.On the Insert menu, click Exception. (Alternatively, click the Exception toolbar button.)
2.Select Create WSDL-fault.
|Note:||If the Create WSDL-fault option is disabled and you see the message "No faults for this operation", this means that no faults exist in the WSDL file, and, consequently, none can be added in MapForce.|
For an example of a mapping which contains a Web service fault, open the following sample MapForce project: <Documents>\Altova\MapForce2023\MapForceExamples\TimeService\TimeService.mfp. Double-click the mapping (operation) getTimeZoneTime.mfd.
In the mapping above, the exception should be triggered when n0:timezone is not equal to UTC.
•The equal function checks to see if timezone equals UTC, with the bool result being passed on to the filter.
•If the condition is false, i.e. something other than UTC, the on-false parameter of the filter activates the Fault:errorSoapOut exception and the mapping process is halted. (Note that you can also connect the exception to the on-true parameter, if that is what you need.)
•Two sets of error text are supplied by the SoapFault message.
It is very important to note the filter placement in the example:
•Both parameters of the filter component, on-true and on-false, must be mapped. One of them needs to be mapped to the fault component, and the other, to the target component that receives the filtered source data. Otherwise, the fault component will never be triggered.
•The exception and target components must be directly connected to the filter component. Functions or other components may not be placed between the filter and either the exception, or target components.