Java calls dataset returned by. Net XML Web Services

Source: Internet
Author: User
Tags net xml

1. Overview

ManyProgramYou have asked this question: "The result returned by my web service is a DataSet object, but if my client is not used. net write (so there is no built-in dataset type ),

 

How can we call this web service and access data in dataset? ".

To solve this problem, we should first say: 1) In a programming environment where multiple languages coexist, it is not suitable for Data Types similar to dataset that only belong to a specific language. Both XML Web Services and CORBA environments should use arrays of simple data types and simple data types as much as possible. 2) You should carefully decide whether to return a large amount of data through the web service. Because the overhead of network transmission includes both the time when an HTTP connection is established and the time when data is transmitted, you need to find an appropriate balance between reducing the number of access servers and reducing the amount of network transmission. If not required, it is not suitable for transmitting data tables containing dozens or hundreds of data records through Web Services.

Then, as far as the problem is concerned ,.. NET web services can be directly returned by other non. net client resolution, because even the dataset type return value, will be reached by the table XML format and then transmitted. The following example shows a web method with the dataset type returned and the XML format data returned after being called:

2. Create. NET web services and return the data set

[webmethod]
Public dataset getpersontable (string Str)
... {
datatable table = new datatable ("person");
table. columns. add ("name");
table. columns. add ("gender");
table. rows. add (New String [2]... {"Alice", "female"});
table. rows. add (New String [2]... {"Bob", "male"});
table. rows. add (New String [2]... {"Chris", "female"});
table. rows. add (New String [2]... {"Dennis", "male"});
table. rows. add (New String [2]... {"Eric", "male"});

Dataset dataset = new dataset ("persontable ");
Dataset. Tables. Add (table );

Return dataset;
}
3. Call. NET web services in Java to process the returned data set

Try ...{

String wsdlurl = "http: // localhost/website1/service. asmx? OP = getpersontable ";
String soapactionuri = "http://tempuri.org/GetPersonTable ";

Service = new service ();
Call call = (CALL) service. createcall ();
//
Call. setoperationname (New QNAME ("http://tempuri.org/", "getpersontable "));
Call. settargetendpointaddress (New java.net. URL (wsdlurl ));
Call. addparameter ("A", org. Apache. axis. encoding. xmltype. xsd_string,
Javax. xml. rpc. parametermode. In );
Call. setreturntype (Org. Apache. axis. encoding. xmltype. xsd_schema );
Call. setusesoapaction (true );
Call. setsoapactionuri (soapactionuri );

Object [] objs = new object []... {"ssss "};
Object res = call. Invoke (objs );
System. Out. println (RES );
Schema schema = (schema) RES;

Defaulttablemodel model = new defaulttablemodel (New String []... {"name", "gender"}, 0 );
Schema. get_any () [1]. getchildnodes (). getlength ();
Int nlength = schema. get_any () [1]. getchildnodes (). Item (0). getchildnodes (). getlength ();
String name = "N/";
String gender = "N/";
For (INT I = 0; I <nlength; I ++)
...{
If (schema. get_any () [1]. getchildnodes (). item (0 ). getchildnodes (). item (I ). getchildnodes (). item (0 ). getnodename (). equals ("name "))
...{
Name = schema. get_any () [1]. getchildnodes (). item (0 ). getchildnodes (). item (I ). getchildnodes (). item (0 ). getfirstchild (). getnodevalue ();
}
If (schema. get_any () [1]. getchildnodes (). item (0 ). getchildnodes (). item (I ). getchildnodes (). item (1 ). getnodename (). equals ("gender "))
...{
Gender = schema. get_any () [1]. getchildnodes (). item (0 ). getchildnodes (). item (I ). getchildnodes (). item (1 ). getfirstchild (). getnodevalue ();
}
Model. addrow (New String []... {name, gender });
This. jscrollpane1.getviewport (). Add (jtable1, null );
}
Jtable1.setmodel (model );
}
Catch (exception ex)
...{
System. Err. println (ex. tostring ());
}
4. Summary

From the previous descriptions and Code As you can see, for "How to Use in Java/Delphi. net web service returned dataset ", although in non. it is difficult to directly accept the returned values of the dataset type in the. NET language environment, but there can be other solutions.

Related Article

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.