首页 > 代码库 > webservice通用客户端代码

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通用客户端代码