您的位置:首页 > 编程语言 > Java开发

JAVA调用webservice(不自动生成客户端)

2013-03-22 18:21 501 查看
AXIS调用方法:

String endpoint = "http://****?wsdl";

org.apache.axis.client.Service service = new

org.apache.axis.client.Service();

org.apache.axis.client.Call call = (org.apache.axis.client.Call)

service.createCall();

call.setTargetEndpointAddress(endpoint);

call.setOperationName(new

QName("***","GetPath"));//

call.addParameter("paramXml", org.apache.axis.encoding.XMLType.XSD_STRING,

javax.xml.rpc.ParameterMode.IN);

call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

String temp ="111";

String result = (String) call.invoke(new Object[] { temp });

System.out.println("result is " + result);

AXIS2调用方法:

RPCServiceClient serviceClient = new
RPCServiceClient();
Options options =serviceClient.getOptions();
EndpointReference targetEPR = new
EndpointReference(url);
options.setTo( targetEPR );
options.setTimeOutInMilliSeconds( 10000 );
String method = "GetPath";//webservice的方法名
String xml =
"111";
Object[] param = new Object[] {xml};
QName opName = new
QName( "***", method );
Class[] returnTypes = new Class[]{String.class};
Object[] results =serviceClient.invokeBlocking( opName, param, returnTypes );
System.out.println(results[0].toString());

CXF调用方法(依赖jdk1.6,与老版本spring冲突):

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
org.apache.cxf.endpoint.Clientclient = dcf.createClient(url);
Object[] param = null;
String method = "GetPath";// webservice的方法名
String xml = "111";
param = new Object[] { xml };
Object[] obj = client.invoke(method,param);
System.out.println(obj[0].toString());

xfire调用方法:

Client client = null;
client = new Client(new URL(wsUrl));
Object[] param = null;
String method =
"GetPath";// webservice的方法名
String xml = "111";
param = new Object[] { xml };
Object[] obj = client.invoke(method, param);
System.out.println(obj[0].toString());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: