Server Faults
On the wire, a SOAP 1.1 server returns all internal exceptions, or server faults, either as a client or server SOAP fault message. When a request is invalid, the server returns a client SOAP fault message. If a request results in a SOAP client fault, sending the same request again will result in another SOAP client fault. By contrast, a server returns a SOAP server fault to indicate a problem unrelated to the content of the request. If the application sends the same request again, the request may succeed. Service endpoint implementations may generate a server fault and will generate either a SOAP client or SOAP server fault depending on the type of exception thrown.
You can detect any errors you want to watch for in your service and return them to the client as an instance of one of the defined fault messages in the WSDL. Simply construct the desired fault message type instance and throw it. The fault is caught in the message handler, which constructs a SOAP server or SOAP client fault message and sends it to the client.
Here is an example that causes the server exception to generate a SOAP server fault message:
 
throw AFaultMessage_message("This is the explanation of the fault",
rwsf::XmlName("Server",rwsf::XmlNamespace("SOAP-ENV",
"http://schemas.xmlsoap.org/soap/envelope/")),
"Error: some kind of fault");
The rwsf::XmlName parameter inserts a SOAP server fault code in the SOAP fault message. To construct a standard SOAP server fault message, define the parameter exactly as shown here. The first string parameter becomes the detail entry of the SOAP fault message, and the last string parameter becomes the human-readable fault string entry.
This example throws an exception resulting from invalid client input, generating a SOAP client fault message.
 
rwsf::Decimal
AccountServlet::getAccountBalance(const std::string& user,
const std::string& password)
{
try {
Account acct(user, password);
return acct.getBalance();
}
 
catch (const AccountInvalidLoginError& e) {
throw rwsf::ClientFault(e.what());
}
}
Note that the sample translates a specific exception type to a SOAP client fault on the wire. If an exception is not handled in the server operation, it is propagated as a SOAP server fault on the wire.