Recipe 15.5. Throwing SOAP Faults15.5.1. ProblemYou want 15.5.2. SolutionCall the <?php Or throw a SOAPFault: <?php You can also return a 15.5.3. DiscussionThe SOAP specification has a standard way of indicating errors: SOAP faults. SOAP faults are very similar to the OO concept of exceptions. In fact, While you can indicate SOAP faults in a number of ways, the easiest is to tHRow an instance of the SOAPFault class, passing an error code and an error string to the constructor, as shown in Example 15-8. Throwing a SOAP fault
In Example 15-8, you throw a SOAPFault when These two values are mapped to the SOAP 1.1 specification's faultcode and faultstring elements, respectively. At the time of this writing, there is not support for SOAP 1.2style SOAP faults. Normally, the error code is used to allow a program to process the error, while the error message is used to let a human understand what occurred'usually through a logfile or by printing it out. Unlike HTTP and status codes, there is no convention for SOAP error codes. For example, the 500 block is not reserved for server errors. You have the freedom to make up whatever set of codes you want. However, the SOAP extension will automatically set the HTTP status code to 500 when you issue a SOAP fault. This is required by the SOAP specification. You cannot use an HTTP status code other than 500. Besides throwing a SOAPFault, you can also return one from your method, or invoke the SOAPServer::fault( ) method. These all generate the same SOAP fault data, so it's a matter of personal preference or coding situation. Instead of using SOAPFault directly, you can also subclass it and use that class instead. This allows you to implement an integrated logging system, for example: <?php SOAP faults are automatically generated when you do something that generates an error, such as calling an undefined function. 15.5.4. See AlsoRecipe 14.10 for catching SOAP faults in a SOAP client. |
Wednesday, January 20, 2010
Recipe 15.5. Throwing SOAP Faults
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment