XML WebService Complete Instance parsing (III.)

Source: Internet
Author: User
Tags add format continue query reference resource string tostring
Web|xml

Next to the article, let's briefly explain the Getsiteadata (string assignname) function.

function is simple, but to return the query results, the data format is XmlDataDocument. When the query fails (no matching query results), we construct an XML that returns an empty record. Otherwise, we will generate a XmlDataDocument after the query dataset , and then, because of the project's need, I added a loop to add the nodes that are not in the dataset, the name of the site. After that, we have completed an XML data document that conforms to our desired format and we return it.

OK, so here's the WebService method function (here's a Web service method, later), and then our task is how to call it. First compile the WebService project, assuming that our service is for resource site A, We may as well call it servicea. Run the asmx file separately, execute the Getsiteadata (string assignname) method, and you will be prompted to enter the parameters, you enter the content to search for, point to confirm, will return you an XML data, and on IE display, That's what you're searching for, pull.

Here on the work of ServiceA, in our project, it is a resource site a provides services, meaning that it queries the data will be all from site A, and site a resources added in this project also has a special project to achieve.

Okay, let's get back to business. Here I introduce vs call WebService method, in fact, other platform invocation method is very similar. First we introduce the Web reference method, which I strongly recommend to use when debugging, very convenient. Right-click the reference, point to add a Web reference, Enter your webservice address, such as: Http://localhost/aspxproject/WebServiceSolution/SiteBService/service1.asmx, You have to make sure that the WebService you enter exists. Then you can quote, note: Web reference names are the namespaces of the webservice you join. For example, you enter: SiteA, the instantiation of the service will be like this: Sitea.service1 servicea= The new Sitea.service1 ();(Service1 is the class name of the service).

Having done this, the call to the service seems to have become so simple that we have implemented a remote instantiation, and the next remote call is just as easy. The following is the binding code of the Resource Collection station Servicegathersite (only collect information of site a)

Binding Data
public void Binddata ()
{
Servicea=new Sitea.service1 ();
DataSet ds=new DataSet ();
XmlNode XmlNode1;
XmlDataDocument xd=new XmlDataDocument ();
StringBuilder xmlString1;
Xmlnode1=servicea.getsiteadata (Strsearch);
if (xmlnode1==null)//--stored procedure execution failed
Return

Xmlstring1=new StringBuilder (Xmlnode1.outerxml);
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 ();
}

This code gives the solution of XML conversion to DataSet, although this is not necessary, but after all, in the ASP.net, the dataset occupies a heavy role, everyone knows. Other friends please see first (hehe, the master on the exemption), In the next article there will be some explanations for it and solutions for multiple service distribution calls, wrote three, found that there seems to be some friends to see, then I will shortcoming continue to write down well, we have any comments also want to put forward, under the understanding of the existence of bias is also inevitable, hope understanding:

Well, it's not too early, rest go, next time to continue:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.