Handling Errors
Errors can occur for any number of reasons. If the request cannot find the service, an error will occur. If the request makes it to the server but the server rejects it, an error will occur. If the SOAP server detects an error, it should return a SOAP response that contains a SOAP fault. This will contain a description of the problem. Any error will be reported as a standard DataFlex error. If the error is a SOAP Fault error, the error description provided by the service will be displayed.
The property peTransferStatus can be tested after a call to see if your web-service call succeeded. If the property’s value is wssOk, the call succeeded. All possible, and some less desirable, values for peTransferStatus are:
-
wssOk
Request succeeded -
wssHttpRequestFailed
HTTP request failed -
wssBadRequest
Bad or missing data sent -
wssInvalidContentType
Invalid contentType received -
wssNoData
No data was received -
wssNotXml
Received data not in proper XML format -
wssNotSoap
Received XML data not in proper SOAP format -
wssInvalidSoap
Received SOAP data not formatted according to service description -
wssSoapFault
SOAP Fault Returned.
Fault-code returned inpsFaultCode
Fault-description returned inpsFaultString
You can use this status to properly handle failed service calls. For example:
Procedure OnClick
string sFirst sLast sReply
Integer eStatus
Get Value of oFirst to sFirst
Get Value of oLast to sLast
Get wsHello of oWSHelloService sFirst sLast to sReply
Get peTransferStatus of oWSHelloService to eStatus
If (eStatus = wssOk) begin
Set Value of oReply to sReply
End
Else begin
Set Value of oReply to "Error"
end
End_Procedure // OnClick
Under some circumstances, you may wish to trap an error and handle it yourself. You can suppress errors by setting the client web-service property pbSuppressLastError to true. When true, errors are not reported, and it is up to you to determine how to handle the error. If peTransferStatus is not wssOk, you can manually generate an error by getting the error text for the last error and creating your own error. The error text for any error status is obtained by sending the TransferErrorDescription message. For example:
Procedure OnClick
string sFirst sLast sReply
string sError
Integer eStatus
Get Value of oFirst to sFirst
Get Value of oLast to sLast
Get wsHello of oWSHelloService sFirst sLast to sReply
Get peTransferStatus of oWSHelloService to eStatus
If (eStatus = wssOk) begin
Set Value of oReply to sReply
End
Else begin
// we know we have an error and we know the type.
// Get the error message for this error
Get TransferErrorDescription eStatus to sError
Set Value of oReply to sError
end
End_Procedure // OnClick
Under certain circumstances, you may need to see the actual SOAP requests and responses to determine the source of errors. A helper object is provided to do that and is described below. In addition, the client object maintains the XML request, response, and return object of the last call. Those are maintained as XML DOM objects and are pointed to by the properties phoSoapRequest and phoSoapResponse. These are for advanced use only.