Monday, November 15, 2010

Send XML Request to Web service in Web Performance Test

In webservice send request three ways.
1. with variables
2. Array format
3. Xml Foramt

Below code using for send XML Request to web service

1. Load XML schema file to reference with below navigation
a. Right click on Project
b. click on Add
c. Click on New Item 
d. in “Add New Item - “ window Select on Resource File and give the name and click on ADD button 
e. It adds “Resources” folder and “ Name.resx” file to the Project 
f. Click on “ .resx” file and in open window Click on beside “Add Resource” arrow and click on “Add Existing File…” menu 
g. Select the required file path in “Add existing file to resources” window and click on “Open”
h. It add to the project and displays under Resources folder

2. In the .CS file code add below code for xml request file
XmlDocument RequestXMLFile=new XmlDocument();
XmlDocument xmlDoc=new XmlDocument();
// get the file from resource folder
String xmlData=resource.xmlfile name;
// Load the xml file
xmlDoc.LoadXml(xmlData);
//Messagebox.Show(xmlDoc.InnerXml);
// below code for xml node names naming space handling purpose

XmlNameTable xnt= xmlDoc.NameTable;
XmlNameSpaceManager nm=new XmlNameSpaceManager(xnt);
Nm.AddNamespace(“var1”,”http;//url”);
// assign the value for xpath
XmlNode nodevar=xmldoc.SelectSingleNode(“/var1:xmlnode1/var1:xmlnode2”,nm);
Nodevar.InnerText=this.Context[“DataSource1.csvfile#csv.columnname”].ToString();
Request1Body.BodyString=xmldoc.InnerXml;
Request1.Body=request1Body;

No comments:

Post a Comment