Through the previous introduction, we should probably know how to write and call WebService. Next we will talk about how to use the service provided by WebService. Below is a piece of code, which is relatively simple:
Private void button#click (Object sender, system. eventargs E)
{
// Localhost. service1 A = new windowsapplication1.localhost. service1 ();
// A. helloworld ();
//
// D. url = "";
// D. getsiteadata ();
// D. helloworld ();
//
String strsearch = "123 ";
Servicea. service1 A = new servicea. service1 ();
Serviceb. service1 B = new serviceb. service1 ();
Iasyncresult AR1;
Iasyncresult AR2;
Dataset DS = new dataset ();
Xmlnode xmlnode1, xmlnode2;
Xmldatadocument XD = new xmldatadocument ();
Stringbuilder xmlstring1, xmlstring2;
// -- Simple asynchronous call
AR1 = A. begingetsiteadata (strsearch, null, null );
AR2 = B. begingetsiteadata (strsearch, null, null );
Xmlnode1 = A. endgetsiteadata (AR1 );
Xmlnode2 = B. endgetsiteadata (AR2 );
//----------
If (xmlnode1 = NULL & xmlnode2 = NULL )//--
Return;
Xmlstring1 = new stringbuilder (xmlnode1.outerxml );
Xmlstring2 = new stringbuilder (xmlnode2.outerxml );
Xmlstring1 = makenewxmlstring (xmlstring1, xmlstring2); // generate a new XML
If (xmlstring1.tostring (). Equals (""))
Return;
XD. loadxml (xmlstring1.tostring ());
DS. readxml (New xmlnodereader (xd ));
Datagrid1.datasource = Ds. Tables [0]
}
// Generate new XML
Public stringbuilder makenewxmlstring (stringbuilder str1, stringbuilder str2)
{
Str1 = str1.replace ("","");
Str2 = str2.replace ("","");
Str1.append (str2.tostring ());
Return str1;
}
This code is run in a Windows application. If it is an Asp.net application, you need to change it to the following:
Datagrid1.datasource = Ds. Tables [0]; followed by datagrid1.databand ();