7.6. Communicating Errors

SOAP provides a standard mechanism for reporting error information using the <soap:Fault> element as discussed in Chapter 3. When using .NET, any exceptions not caught in the Web method get reported to the client as a <soap:Fault>. Similarly, .NET clients throw a SoapException whenever they receive a <soap:Fault>. In the simplest case, you can communicate errors from a service by throwing an exception, for example:

Throw New Exception("This is the error information")

For more sophisticated scenarios, you can send structured error information as XML elements inside <soap:Fault>. To do this, you create a new SoapException and pass it an array of XML elements that you want to send to the client. SoapException has six ...

Get Real World XML Web Services: For VB and VB .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.