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.
hi i am new to this Webservice testing using QTP. my question here is we usually add keystore in SOAPUI tool for our tesing and sending SOAP request as well as we provide End point now how to add same Keystore and Endpoint in QTP for webservice testing.
I tried all documents on QTP but none of them were helpful.
Please help me if anybody know the solution.
thanks,
Hi Ankur,
I’m facing issue while testing WebServices using QTP. I’ve installed ‘Web Services’ Add-in. I get 403 error when I try to send a request. When I pass WSDL url in the Web Services Wizard it brings up all the exposed methods. however when I pass valid databy editing the xml structure and execute the script I get 403 error. Same request works fine on SOAP UI tool. I even tried w3school’s sample WSDL (temp converter) it gave me Error 417. Please find below code and error message. thanks.
‘ MSIServiceService Web service object steps
Set createService = WebService(“MSIServiceService”).createService(XMLWarehouse(“createService”))
WebService(“MSIServiceService”).Check CheckPoint(“createService”)
Error Message:
The createService operation call failed.
The .NET Framework 2.0 WSE 3.0 toolkit returned the following error:
Exception from: System.Web.Services
The request failed with HTTP status 403: Forbidden.
Line (2): “Set createService = WebService(“MSIServiceService”).createService(XMLWarehouse(“createService”))”.
Thanks and Regards,
Dilip
Here is some sample VBScript code to make web services SOAP queries:
http://gallery.technet.microsoft.com/scriptcenter/deed3efb-1e11-4e7e-8bfd-96a981de5c35
Hi All,
I tried using following code after adding the WSDL file through Webservices wizard
Dim ssr0XML,XMLstr
Set ssr0XML = XMLUtil.CreateXMLFromFile(“C:\Documents and Settings\user\Desktop\ip\Input.xml”)
XMLstr = ssr0XML.ToString
‘ xyzGatewayExtnExport1_xyzGatewayExtnHttpService Web service object steps
LocalParameter(“initiatexyzRequest”) =WebService(“xyzGatewayExtnExport1_xyzGat”).initiatexyzRequest(XMLstr)
During execution I am getting following error:
The initiatexyzRequest operation call failed.
The .NET Framework 2.0 WSE 3.0 toolkit returned the following error:
Failed to create client’s proxy object.
Exception from: System
Invalid URI: The format of the URI could not be determined.
Line (6): “LocalParameter(“initiatexyzRequest”) =WebService(“xyzGatewayExtnExport1_xyzGat”).initiatexyzRequest(XMLstr)”.
Please if anyone has faced such a issue and knows the solution please share it ..
Thanks,
Shree
@Chad…would you mind to post your link for your example. Thx much!
@Chad: You can contact me using the contact form http://www.learnqtp.com/contact/
I successfully used Keyword View and Datatable combination and got the Web Service Working. There are a couple of things to explain before we start the webservices. I used QTP 10 for web services. Keyword View, Data Table and inbuilt XML check points are only necessary to for successfully testing web services in most of the cases. if we are going for descriptive programming i will say we are not making use of most of the built in facilities provided by QTP as – is and re-inventing the wheel. I will host a simple example in You Tube and will place the link here for your reference. I am searching for some recording tools and screen captureing mechanism.
The Web Service name comes from the wsdl after you loaded using QTP Services Wizard. Once you do at least one API selection, the service will be loaded in your object repository.
We also constructed our own XML file and using raw WebService(“X”).SendRequest method.
One problem that I have is that QTP does not seem to be able to capture valid/detailed error message (e.g. No record found). GetLastError or LastResponse methods will only contain generic 500 error.
Did anyone found way to retrieve detailed error messages?
Hi Ankur,
I’m new to QTP – learning from various sites and the UserGuide. In your example above, how do you get the webservices name. Or in other words, can you provide a detailed example for WebServices. Your help is much appreciated.
Thanks
Ruby
Hey everyone. I had a hell of a time getting QTP to call a web service successfully but finally got it working using the code below:
Set ssr0XML = XMLUtil.CreateXMLFromFile(“C:\ScheduleRequest.xml”)
XMLstr = ssr0XML.ToString
Set RequestSchedule = WebService(“AutomatedSchedulingService”).RequestSchedule(XMLstr)
I was having all sorts of issues with invalid characters and internal server (500) errors using the xml generated by the QTP WebService wizard. Finally I just went ahead and manually constructed the xml and hey presto!
Hope this helps.
i tried following
Set ssr0XML= XMLUtil.CreateXMLFromFile(“G:\work related\Automation\Webservices\XMLs\validate email”)
XMLstr = ssr0XML.ToString
WebService(“ValidateEmailService”).SendRequest “Isvalidate”, XMLstr
but i m getting error “The constructor to deserialize an object of type ‘Mercury.QTP.WS.NET_Client.NetToolkitException’ was not found.”…
please any one knows how to solve this…..?
can someone pl. share a detailed example. I tried a few different things, but can seem to get the response from teh soap post.
Hi Ankur,
This is chandra, I need your hlp..
I am working in Webservices, but I am new to this can plz tell me how to start working on it…
I don’t know how to send requst and take response….
Can you plz help me…if posible plz send one example..
chandra.rao@enfs.com.
Thanks
— Chandra
you may first install add-ins for web services then open your QTP and then assign the URL of wsdl or otherwise second option is to select the wsdl file.
What libruery should I include to allow function WebService?
Hi!
It would be nice to see an example with real WSDL-Service.
Thanks.