soap_request
| Web Services Functions (SOAP, WEB_SERVICE, Silverlight) |
Performs a SOAP request.
int soap_request( const char *StepName,ExpectedResponse, URL, <XMLEnvelope>, [Attachments,] LAST );| StepName | The name of the step, as it appears in the test tree. Any text can be used. |
| ExpectedResponse | The type of response to accept. See details below. |
| URL | The URL (Uniform Resource Locator) of the web service to load. |
| XMLEnvelope | For the following list of required elements, use the following string format: "Element=value"SOAPEnvelope: the XML packet sent to the server.Snapshot: the name of the .inf file containing a snapshot of the step.ResponseParam: the name of the output parameter in which to store the server response. |
| Attachments | For details, see Attachment Specifications. |
| LAST | A marker which indicates the end of the List of specifications |
The soap_request function performs a SOAP request. It sends a SOAP packet to the specified URL and receives the server response.
The expected response is one of the following:
| Value | Effect |
|---|---|
| "ExpectedResponse=SoapResult" | Accept SOAP output responses and fail on SOAP faults. |
| "ExpectedResponse= SoapFault" | Accept SOAP faults and fail on SOAP output responses. |
| "ExpectedResponse= AnySoap" | Accept both SOAP output and SOAP fault responses. |
This function is generated when you record a SOAP session over HTTP without providing the WSDL file of the corresponding Web Service.
Return Values
This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure. Note that in many cases, this return value indicates the technical success of the function, and not the result. For example, a function that registers a string to be found in a subsequent step returns LR_PASS to indicate that the registration was successful. This does not indicate that the string was found in the server response.
Parameterization
The following arguments may be parameterized: URL, XMLEnvelope, value (of elements).
Examples
Example 1
In the first example, the soap_request function sends a SOAP packet to http://api.google.com/search/beta2.
web_add_header("SOAPAction",
"\"urn:GoogleSearchAction\"");
soap_request("StepName=google",
"ExpectedResponse=AnySoap",
"URL=http://api.google.com/search/beta2",
"SOAPEnvelope= "
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope "
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"xmlns:soapenc=\""
"http://schemas.xmlsoap.org/soap/encoding/\" "
"xmlns:tns=\"urn:GoogleSearch\" "
"xmlns:types=\"urn:GoogleSearch/encodedTypes\" "
"xmlns:xsi=\""
"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns:xsd=\""
"http://www.w3.org/2001/XMLSchema\">"
"<soap:Body soap:encodingStyle=\""
"http://schemas.xmlsoap.org/soap/encoding/\">"
"<tns:doGoogleSearch>"
"<key xsi:type=\"xsd:string\">"
"j1bV/rJGA3o10po6iUtemzqHHbb4eH79</key>"
"<q xsi:type=\"xsd:string\">"
"Product </q>"
"<start xsi:type=\"xsd:int\">0</start>"
"<maxResults xsi:type=\""
"xsd:int\">10</maxResults>"
"<filter xsi:type=\"xsd:boolean\">false</filter>"
"<restrict xsi:type=\"xsd:string\" />"
"<safeSearch xsi:type=\"xsd:boolean\">"
"false</safeSearch>"
"<lr xsi:type=\"xsd:string\" />"
"<ie xsi:type=\"xsd:string\" />"
"<oe xsi:type=\"xsd:string\"/>"
"</tns:doGoogleSearch>"
"</soap:Body>"
"</soap:Envelope>",
"Snapshot=t1.inf",
"ResponseParam=result", LAST );
Example 2
In the second example, the soap_request function uploads and downloads files.
web_add_header("SOAPAction", "\"\"");
// Soap_Request for upload file
soap_request("StepName=MimeUploadFileWithSoapRequest",
"URL=http://myServer:8080/axis/services/MimeService",
"SOAPEnvelope="
"<?xml version=\"1.0\" encoding=\"UTF-8\"standalone=\"no\"?>"
<soap:Envelope xmlns:soap=\"http://sc"
"hemas.xmlsoap.org/soap/envelope/\"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xm"
"lns:xsd=\"http://www.w3.org/2001/XMLSchema\"
"xmlns:tns=\"http://DefaultNamespace\" xmlns:types"
"=\"http://DefaultNamespace\"
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<soap:Body soap:encodingStyle="
"\"http://schemas.xmlsoap.org/soap/encoding/\">"
"<tns:MimeUploadFile><"in0 xsi:type=\"xsd:string\">d"
":\\temp\\myUploaded1.txt</in0></tns:MimeUploadFile>"
</soap:Body></soap:Envelope>",
ATTACHMENTS_FORMAT_MIME,
ATTACHMENT_ADD,"FileName=d:\\temp\\attachment.in",
"ContentType=text/plain","Id=12345",
LAST );
// Soap_Request for download file
soap_request("StepName=MimeDownloadFileWithSoapRequest",
"URL=http://myServer:8080/axis/services/MimeService",
"SOAPEnvelope="
"<?xml version=\"1.0\" encoding=\"UTF-8\"
"standalone=\"no\"?><soap:Envelope xmlns:soap=\"http://sc"
"hemas.xmlsoap.org/soap/envelope/\"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xm"
"lns:xsd=\"http://www.w3.org/2001/XMLSchema\"
"xmlns:tns=\"http://DefaultNamespace\" xmlns:types"
"=\"http://DefaultNamespace\"
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"
<soap:Body soap:encodingStyle="
"\"http://schemas.xmlsoap.org/soap/encoding/\">
<tns:MimeDownloadFile>"
"<in0 xsi:type=\"xsd:string\">"
"d:\\temp\\myUploaded.txt</in0></tns:MimeDownloadFile>"
"</soap:Body></soap:Envelope>",
ATTACHMENT_SAVE_BY_INDEX,
"Index=1","ParamName=pAttachmentContent",
LAST );

