axis2开发webservice客户端的3种方式

http://harveyzeng.iteye.com/blog/1849720

==========

RPC方式

 

import javax.xml.namespace.QName;

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

 

public class HelloWorldTest {
public static void main(String[] args)
{
String xmlStr="huang";
String url="http://localhost:8080/ws1/HelloWorldPort";
String method="printStr";

HelloWorldTest.invokeRemoteFuc(xmlStr,url,method);

}

public static String invokeRemoteFuc(String xmlStr,String url,String method){
String xml=null;
try{
RPCServiceClient client= new RPCServiceClient();
EndpointReference targetEPR= new EndpointReference(url);
Options options=client.getOptions();
options.setTo(targetEPR);
//options.setAction("urn:HelloWorld");
QName opAddEntry=new QName("http://yourcompany.com/",method);
Object[] opAddEntryArgs = new Object[] {xmlStr};
Class[] classes=new Class[]{String.class};
xml=(String)client.invokeBlocking(opAddEntry, opAddEntryArgs,classes)[0];
System.out.println(xml);


}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
long end = System.currentTimeMillis();
}

return xml;
}



}

你可能感兴趣的:(webservice)