webservice通用客户端代码
Posted Perry Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webservice通用客户端代码相关的知识,希望对你有一定的参考价值。
package test;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.description.OperationDesc;
import org.apache.axis.description.ParameterDesc;
public class TestWS2 {
public static void main(String[] args) {
try {
// Web Service路径
String endpoint = “http://10.1.3.142:8001/ats/GetUserFund”;
//String endpoint = “http://10.1.3.113/ls/services/ATSTransWSService”;
OperationDesc oper = new OperationDesc();
// getExtendSystemXmlData ->Web Service供调用的方法
oper.setName(“getExtendSystemXmlData”);
ParameterDesc param = new ParameterDesc(new javax.xml.namespace.QName(“”, “arg0”), ParameterDesc.IN,
new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “string”), java.lang.String.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName( “http://www.w3.org/2001/XMLSchema”, “string”));
oper.setReturnClass(java.lang.String.class);
oper.setReturnQName(new javax.xml.namespace.QName(“”, “arg0”));
oper.setStyle(org.apache.axis.constants.Style.RPC);
oper.setUse(org.apache.axis.constants.Use.ENCODED);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setUseSOAPAction(true);
call.setSOAPActionURI(“”);
call.setOperation(oper);
call.setOperationName(new QName(“http://impl.getUseFund.webservice.ats.fund.hundsun.com/”,”getExtendSystemXmlData”));
//文档规范的请求XML;
String xmlStr = “<?xml version=\”1.0\” encoding=\”UTF-8\”?>”
+ “<PACKET type=\”REQUEST\” version=\”1.0\”>”
+ ” <HEAD>”
+ ” <REQUEST_TYPE>09</REQUEST_TYPE>”
+ ” <SYSTYPE>101</SYSTYPE>”
+ ” </HEAD>”
+ ” <BODY>”
+ ” <DETAILITEM>”
+ ” <RECORDSOURCE_BATNO>2590</RECORDSOURCE_BATNO>”
+ ” <ORIGIN_NOTE>5138</ORIGIN_NOTE>”
+ ” </DETAILITEM>”
+ ” </BODY>”
+ “</PACKET>”;
// res->返回文档标准的回执XML,xmlStr->文档规范的请求Xml
String res = (String) call.invoke(new Object[] { xmlStr });
System.out.println(res);
} catch (Exception e) {
e.printStackTrace();
}
}
}
以上是关于webservice通用客户端代码的主要内容,如果未能解决你的问题,请参考以下文章
在idea中,怎么生成cxf webservice的客户端代码
Axis2生成wsdl客户端代码并实现webservice调用