WebService Learning notes, Axis2 passing object array, non-stub mode

Source: Internet
Author: User
Tags stub wsdl

Or use my Blog "WebService study notes, Axis2 transfer simple objects, non-stub mode
"Example of:

First Build Servicetest.java

Package sample.ws.service;

Import Sample.ws.pojo.Person;

public class Servicetest {
/**
* Very simple we'll just send the person[] back to
* @param person
* @return
*/
Public person[] Getperson (person[] person) {

Person Person1 = new person ();
Person1.setage ("20");
Person1.setname ("Zhang San");
//
Person Person2 = new person ();
Person2.setage ("30");
Person2.setname ("John Doe");
//
person[] Person3 = new person[2];
Person3[0] = Person1;
PERSON3[1] = Person2;
SYSTEM.OUT.PRINTLN ("AfD");
return person;
}


}

Pojo Person.java not change

public class person{

private String name;

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

}

Services.xml also remain unchanged;

<?xml version= "1.0" encoding= "UTF-8"?>


<service name= "Testservice" scope= "Application" >
<description>TestService</description>

<messageReceivers>
<messagereceiver
mep= "Http://www.w3.org/2004/08/wsdl/in-only"
class= "Org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
<messagereceiver
mep= "Http://www.w3.org/2004/08/wsdl/in-out"
class= "Org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name= "ServiceClass" >
Sample.ws.service.ServiceTest
</parameter>

</service>

=======================================================================

Here is the client:

1, Pojo Person.java remain unchanged

public class person{

private String name;

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

}

2. Requesting Client Ws2pojoclient.java

Package sample.ws.client;

Import Javax.xml.namespace.QName;

Import org.apache.axis2.addressing.EndpointReference;
Import org.apache.axis2.client.Options;
Import org.apache.axis2.rpc.client.RPCServiceClient;

Import Sample.ws.pojo.Person;

public class Ws2pojoclient {

public static void Main (String args[]) throws Java.lang.Exception {

Rpcserviceclient client = new Rpcserviceclient ();

Options option = Client.getoptions ();
Specify the WebService server-side address for client access
EndpointReference Erf = new EndpointReference (
"Http://localhost:9999/Ws2Pojo/services/TestService");

Option.setto (ERF);
Specifies the namespace, specifying the method to invoke
QName name = new QName ("Http://service.ws.sample", "Getperson");
Create Person Object
Person Person1 = new person ();
Person1.setage ("20");
Person1.setname ("Zhang San");

Person Person2 = new person ();
Person2.setage ("30");
Person2.setname ("John Doe");
Create a person array
person[] Person3 = new person[2];
Person3[0] = Person1;
PERSON3[1] = Person2;

Create an object array to transfer
Object[] object = new object[] {Person3};
Create the returned parameter type
class[] Returntypes = new class[] {person[].class};
Call the remote service to get the returned object array
object[] response = client.invokeblocking (Name, object, returntypes);
Cast to person[] Object

Person[] p = (person[]) response[0];
Iterate to get the value we just requested in the past
for (int i = 0; i < p.length; i++) {
System.out.println (P[i].getage ());
System.out.println (P[i].getname ());
}

}
}

Get results:
20
Tom
30
John doe

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.