Probably the most appropriate SOA pattern for later use will be a fault contract, which is essentially a data contract that is wrapped in a SOAPException.
I am posting examples in .NET, as it looks like this is what you are using (and this is what I know :))
In WCF, you can define a DataContract and then decorate your OperationContract interface with the "FaultContract" attribute, which indicates it as a return value:
public partial interface MyServiceContract { [System.ServiceModel.FaultContract(typeof(MyService.FaultContracts.ErrorMessageFaultContract))] [System.ServiceModel.OperationContract(...)] ResponseMessage SOAMethod(RequestMessage request) {...} }
For ASMX web services (as you seem to use from a piece of code), you cannot use this attribute or setting. Therefore, to implement the template you need:
- Define a serializable class for storing exception information (i.e. ErrorData)
- When an exception is thrown in your service, catch it and add information to the ErrorData class in the error handling code li>
Add the serialized ErrorData class to the SoapException class:
SoapException mySoapException = new SoapException(message, SoapException.ServerFaultCode, "", serialzedErrorDataClass);
Throw a SoapException in your code
- On your client side, you need to deserialize the message in order to interpret it.
You seem to have a lot of work to do, but in this way you have complete control over what data is being returned. By the way, this is a template used by ServiceFactory from Microsoft templates and methods for ASMX web services.
source share