How to send a SOAP XML message using the SendRequest method

The user wants to write a test that sends a SOAP XML message to his Web Services gateway.

Example:

Set ssr0XML = XMLUtil.CreateXMLFromFile("D:tempXMLServiceStatusSSR0.xml")
WebService("XOAService_2").SendRequest("ServiceStatus", "ssr0XML")

The first line of the script reads the contents of a valid XML file into a variable named ssr0XML. The second line attempts to send this message to the Web Services application server.

During replay, the user verifies that QuickTest Professional sends the message. However, the content of the message is the string ssr0XML, not the expected XML file. This causes the Web Services server to generate an error. How should a message be sent?

Solution: Using the SendRequest Web Services method

The SendRequest method sends the message specified in the SOAPMessage argument with no modifications and no additional items are appended to the message. Specifically, the message is not affected by previous AddAttachment, AddHeader, AddMessageProtection, AddSecurityToken statements.

object.SendRequest OperationName, SOAPMessage

object The WebService test object.
OperationName The Web service operation to be performed by the request.
SOAPMessage The SOAP request in the form of an XML string. The value should be a valid SOAP envelope, according to the SOAP specifications.

You can retrieve the response to the message sent with this method by inserting a LastResponse statement after it.

Note:
The SendRequest method expects a XML string, not an XML object. So if you are using the XMLUtil object to create an XML object, you will need to use the ToString method to convert the XML object to an XML string. Then you can use it with the SendRequest method.

Set ssr0XML = XMLUtil.CreateXMLFromFile("D:tempXMLServiceStatusSSR0.xml")
XMLstr = ssr0XML.ToString
WebService("XOAService_2").SendRequest("ServiceStatus", XMLstr)

Read this series to understand the basics of WebServices with QTP.

If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS Feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.

Please use QTP forum for posting QTP questions.