Java calls WebService (axis2) Two Methods

Source: Internet
Author: User

 

// Method 1: Generate the client code call method. (This method can simplify a lot of code)
//
// Use the plug-in tool to generate client code for calling. For example, if a service is
// Http: // 127.0.0.1: 8000/axis2/services/helloworld? WSDL

// Save As helloworld. WSDL.

Code is automatically generated, including helloworldproxy. Java

Public static void main (string [] ARGs ){

Uploadproxy up = new uploadproxy ();
Up. setendpoint ("http: // 127.0.0.1: 70/uploadimg/services/uploadimg ");

// The Image Upload fileinputstream is omitted.
Up. updateimage ("", uploadbuffer, 0, 0 ,"","","","");}
// Generated using the plug-inSmssendservicestub. Java. The called client code is as follows:
Public static void main (string [] ARGs) throws exception {
Helloworldstub stub;
Stub = new helloworldstub ();
Helloworldstub. getname helloworld = new helloworldstub. getname ();//
Helloworld. setname ("peipan ");
System. Out. println (stub. getname (helloworld). get_return ());

}

// Method 2: Use axis2.rpc. Client. rpcserviceclient.
// Public static void main (string [] ARGs) throws exception {
// Getwsbyaxis2 Ws = new getwsbyaxis2 ();
// Ws. wsurl = "http: // 127.0.0.1: 8000/axis2/services/helloworld ";
// String result;
// Try {
// Result = ws. getstr ("getname", "peipan ");
// System. Out. println (result );
//} Catch (axisfault e ){
// E. printstacktrace ();
//}
//}

-------------------------------------------------

Package test;
Import javax. xml. namespace. QNAME;

Import org. Apache. axis2.axisfault;
Import org. Apache. axis2.addressing. endpointreference;
Import org. Apache. axis2.client. options;
Import org. Apache. axis2.rpc. Client. rpcserviceclient;

Public class getwsbyaxis2 {
Private Static string endpointurl;
Private Static string qurl = "http://ws.apache.org/axis2 ";
Private QNAME opaddentry;
Public String wsurl;
Public rpcserviceclient setoption () throws axisfault
{
Rpcserviceclient serviceclient = new rpcserviceclient ();
Options = serviceclient. getoptions ();
Endpointreference targetepr = new endpointreference (wsurl );
Options. setto (targetepr );
Return serviceclient;
}

Public QNAME getqname (string option ){

Return new QNAME (qurl, option );
}
// Return string
Public String getstr (string option, string why) throws axisfault
{
Rpcserviceclient serviceclient = This. setoption ();

Opaddentry = This. getqname (option );

String STR = (string) serviceclient. invokeblocking (opaddentry,
New object [] {why}, new class [] {string. Class}) [0];
Return STR;
}
// Returns a one-dimensional string array.
Public String [] getarray (string option) throws axisfault
{
Rpcserviceclient serviceclient = This. setoption ();

Opaddentry = This. getqname (option );

String [] strarray = (string []) serviceclient. invokeblocking (opaddentry,
New object [] {}, new class [] {string []. Class}) [0];
Return strarray;
}
// Return the instance of an object from WebService
Public object GetObject (string option, object O) throws axisfault
{
Rpcserviceclient serviceclient = This. setoption ();
QNAME = This. getqname (option );
Object object = serviceclient. invokeblocking (QNAME, new object [] {}, new class [] {o. getclass ()}) [0];
Return object;
}

//////////////////////////////////////// /Readers can encapsulate their own data types, data types such as int, byte, and float
}

 

 

 

 

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.