The project needs to call another partner's WebService interface, before using the Sax call method, began to grope this, feel this also quite simple, now the realization of their own process to share to everyone, write bad place, hope everyone do not spray.
The detailed code is as follows:
Package Com.ancs.oa;import Java.util.date;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;/** * * @ClassName: Messageservice * @Description: Call WebService incoming 5 parameters * @ author [email protected] * @date: December 25, 2014 PM 5:16:21 */public class Messageservice {public static Object Tooamessage (String a,string b,string c,string D) throws axisfault{//using RPC to invoke WebService Rpcserviceclient Client=new RP Cserviceclient (); Options option=client.getoptions (); Specify the URL to call WebService EndpointReference Targetepr =new endpointreference ("Your WebService Address"); Option.setto (TARGETEPR); Specifies the plus method to invoke and the namespace of the WSDL file//http://testqname opaddentry =new QName ("http://webService.oa.ancs.com", " Docmessageinsert "); Specify the parameter value of the plus method object[] Opaddentryargs = new object[] {a,b,c,d,new Date ()}; Class object specifying the data type of the plus method return value class[] classes = new class[] {StRing.class}; Call the plus method and output the return value of the method try {return client.invokeblocking (Opaddentry,opaddentryargs, classes) [0];} catch (Axisfault e) {/ /TODO auto-generated catch Blocke.printstacktrace ();} return null;}}
Java Call WebService Method (axis)