Question

I'm working on a new Soap Web Service. The previous Web Service used to return an array('error'=>"Please login first"); when an error was encountered. From what I've read, its better to use a SoapFault instead.

The following line is used to call a SoapFault:

throw new SoapFault($faultcode, $faultstring, $faultactor, $faultdetail, $faultname, $headerfault);

I saw that Soap has pre-defined codes, namely: VersionMismatch, MustUnderstand, Client and Server.

Please help me understand by answering/correcting the following:

  1. Can I use my own custom faultcodes like "Auth" or "Error55".
    1. Some use array("namespace", "errorcode"). Should this rather be used? And what should the value of namespace be?
  2. I assume faultstring can be anything for the user like "Please login first".
  3. What is the purpose of faultactor?
  4. faultdetail is an array containing extra detail of the fault. What kind of detail?
  5. what is the purpose of faultname?
  6. what is the purpose of headerfault?
Was it helpful?

Solution

I believe it's generally discouraged to ask multiple questions in a single SO question. Also, most of this would be answered by reading section 4.4, "SOAP Fault", of the SOAP spec.

  1. faultcode

    The faultcode element is intended for use by software to provide an algorithmic mechanism for identifying the fault. The faultcode MUST be present in a SOAP Fault element and the faultcode value MUST be a qualified name as defined in section 3. SOAP defines a small set of SOAP fault codes covering basic SOAP faults...the namespace identifier for [default] faultcode values is "http://schemas.xmlsoap.org/soap/envelope/"

  2. faultstring

    The faultstring element is intended to provide a human readable explanation of the fault and is not intended for algorithmic processing.

  3. faultactor

    "The faultactor element is intended to provide information about who caused the fault to happen within the message path (see section 2). It is similar to the SOAP actor attribute (see section 4.2.2) but instead of indicating the destination of the header entry, it indicates the source of the fault. The value of the faultactor attribute is a URI identifying the source. Applications that do not act as the ultimate destination of the SOAP message MUST include the faultactor element in a SOAP Fault element. The ultimate destination of a message MAY use the faultactor element to indicate explicitly that it generated the fault (see also the detail element below)."

  4. faultdetail is a string, not an array, and should contain

    application specific error information related to the Body element

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top