PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example of SOAPToHTTP
SOAPToHTTP (Example)
Example of SOAPToHTTP
// Standard call that is using the full call to a WebService method
WSparam is MethodWebServiceRequest
WSReponse is MethodWebServiceResponse
 
WSparam.AccountNumber = "123456789"
WSparam.name = "my name"
// etc...
 
// If the XML sent must not be modified:
WSReponse = WebServiceName.WebServiceMethod(WSparam)
IF ErrorOccurred THEN
// The return is not XML or contains invalid XML
Error ("WebService call failed: " + ErrorInfo())
ELSE
// Web service return process
// This Webservice returns an error code in case of a problem: is there an error code?
IF Val(WSReponse.ResponseInformation.Error) > 0 THEN
// Yes...
Error ("Error #" + WSResponse.ResponseInformation.Error,
WSResponse.ResponseInformation.ErrorMessage)
ELSE
Info ("WebService response: ", WSReponse.ResponseInformation)
END
END
// Call to the same Webservice method but with a custom XML sent
WSparam is MethodWebServiceRequest
WSReponse is MethodWebServiceResponse
 
WSparam.AccountNumber = "123456789"
WSparam.name = "my name"
// etc...
 
// Retrieve the HTTP request sent by default with the above parameters
HTTP_request_WS is httpRequest = SOAPToHTTP(WebServiceName.WebServiceMethod, WSReponse)
// Retrieve content, therefore XML, in an XMLDocument variable
XML_request_WS is xmlDocument = XMLOpen(HTTP_request_WS..Content, fromString)
// ------------- Modify XML before sending it
// Handle XML_request_WS to change anything....
XML_request_WS.Envelope.Body.MethodeWebServiceRequest:attribute = "value"
// etc...
// in this part it is possible to modify all or part of the XML
// that will be sent to the Webservice
//-------------
 
// Re-inject the modified XML into the HTTP request
HTTP_request_WS..Content = XML_request_WS.BuildString()
 
// Run the HTTP request to call the WS method
HTTP_return_WS httpResponse = HTTPSend(XML_request_WS)
IF ErrorOccurred THEN
Error ("WebService call failed", ErrorInfo ())
ELSE
// Put the return of the Webservice in
// the variable of the expected type when importing the WebService into the project
// For this we first retrieve the XML source in an XMLDocument variable
XML_return_WS is xmlDocument = XMLOpen(HTTP_return_WS..Content, fromString)
IF ErrorOccurred _OR_ NOT StringStartsWith(HTTP_return_WS..ContentType, ...
[typeMimeSOAP, "text/xml"], ccIgnoreCase) THEN
// The return is not XML or contains invalid XML
Error ("Error, non-XML return ", HTTP_return_WS.. Content)
ELSE
// soap error? (is there an error code or an error message with SOAP standard?)
IF XML_return_WS.Envelope.Body.Fault.faultstring<> "" ...
 _OR_ XML_return_WS.Envelope.Body.Fault.faultCode <> "" THEN
// Error message
sErrorMessage is string = XML_return_WS.Envelope.Body.Fault.faultstring
// Error code
sErrorCode is string = XML_return_WS.Envelope.Body.Fault.faultCode
// Other details about the error (depends on the Webservice)
FOR EACH nodedetail OF XML_return_WS.Envelope.Body.Fault
IF NOT nodedetail..Name IN ("faultstring", "faultCode") THEN
sErrorMessage += [CR] + nodedetail..Name + ": " + nodedetail..Text
END
END
Error("Error returned by the WebService", "Error n°" + sErrorCode, sErrorMessage)
ELSE
// In the XML, we take the part of the SOAP response (first subtag of the Body)
xmlNodeSoapResponse is xmlNode
xmlNodeSoapReponse = XML_return_WS.Envelope.Body..ChildNode[1]
// And we update the variable "WSResponse" which is imported from the WebService
IF xmlNodeSoapResponse..Namespace..Name<>"" THEN
WSResponse..InnerXML = XMLExtractString(xmlNodeSoapResponse..XMLSource, ...
xmlNodeSoapResponse..Namespace..Name+":" + xmlNodeSoapResponse..Name, 1, XMLExact)
ELSE
WSResponse..InnerXML = XMLExtractString(xmlNodeSoapResponse..XMLSource, ...
xmlNodeSoapResponse..Name, 1, XMLExact)
END
 
// Normal handling of the WebService return with WSResponse as in the classic call
// This Webservice returns an error code in case of a problem: is there an error code?
IF Val(WSReponse..ResponseInformation..Error) > 0 THEN
// Yes...
Error ("Error #" + WSResponse.ResponseInformation.Error,
WSResponse..ResponseInformation..ErrorMessage)
ELSE
Info ("WebService response: ", WSReponse..ResponseInformation)
END
END
END
END
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment