Next, let's briefly describe the binding function. first instantiate ServiceA, which is no different from the instantiation of general classes .. next, use xmlNode1 to accept the return value of the function. Next, construct the xml and convert it to dataset. This is a common method. If you are new friends, you 'd better write down this method.
The code for Asynchronously calling two services is provided.
// Bind data
Public void BindData ()
{
IAsyncResult ar1;
IAsyncResult ar2;
ServiceA = new SiteA. Service1 ();
ServiceB = new SiteB. Service1 ();
DataSet ds = new DataSet ();
XmlNode xmlNode1, xmlNode2;
XmlDataDocument xd = new XmlDataDocument ();
StringBuilder xmlString1, xmlString2;
// -- Simple asynchronous call
Ar1 = serviceA. BeginGetSiteAData (strSearch, null, null );
Ar2 = serviceB. BeginGetSiteAData (strSearch, null, null );
XmlNode1 = serviceA. EndGetSiteAData (ar1 );
XmlNode2 = serviceB. EndGetSiteAData (ar2 );
//----------
If (xmlNode1 = null & xmlNode2 = null) // -- stored procedure execution failed
Return;
XmlString1 = new StringBuilder (xmlNode1.OuterXml );
XmlString2 = new StringBuilder (xmlNode2.OuterXml );
XmlString1 = MakeNewXmlString (xmlString1, xmlString2); // generate a new xml
If (xmlString1.ToString (). Equals ("<NewDataSet xmlns = \" \ "> </NewDataSet> "))
Return;
Xd. LoadXml (xmlString1.ToString ());
Ds. ReadXml (new XmlNodeReader (xd ));
DataGrid1.DataSource = ds. Tables ["list"]. DefaultView;
DataGrid1.DataBind ();
}
// Generate new XML
Public StringBuilder MakeNewXmlString (StringBuilder str1, StringBuilder str2)
{
Str1 = str1.Replace ("</NewDataSet> ","");
Str2 = str2.Replace ("<NewDataSet xmlns = \" \ "> ","");
Str1.Append (str2.ToString ());
Return str1;
}
There are two points to note: xml structure and asynchronous calling implementation. Please understand them yourself.
The following describes how to reference webservice through dll. I will only introduce the process.
First, enter the service address in ie, such as: http://www.xxx.com/service.asmx
Then write input http://www.xxx.com/service.asmx? Wsdl
Open it and save it as xxx. wsdl
Run the vs command prompt to compile: wsdl/namespace: SiteA ServiceA. wsdl.
Generate a proxy class with the namespace as sitea
Finally, csc/out: ServiceA. dll/t: library Service1.cs. service1.cs is the proxy file.
Finally, you can reference the dll.
At this point, our example is basically complete. For personal reasons, the last article may be written in a rush, which is very embarrassing.
If you have any need for help or doubt, you can wiseman.net@gmail.com contact me, if the Internet, will certainly return.
From: IT lab