java 调用webservice接口(wsdl)

进入?wsdl链接,查看方法名、参数、命名空间等信息。

import org.apache.axiom.om.OMElement;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;

import javax.xml.namespace.QName; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; /** * Created by liwj on 2017/6/7. */ public class WebServiceTestReal { private static String url=""; public static void main(String[] args) throws Exception { long startTime=System.currentTimeMillis(); String xml=""; // 使用RPC方式调用WebService RPCServiceClient serviceClient = new RPCServiceClient(); // 指定调用WebService的URL EndpointReference targetEPR = new EndpointReference(url); Options options = serviceClient.getOptions(); //确定目标服务地址 options.setTo(targetEPR); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, 30000); options.setProperty(HTTPConstants.SO_TIMEOUT, 30000); //避免文件过早结束 options.setProperty(HTTPConstants.CHUNKED, "false"); String fgNamespace=""; String fgLocalPart=""; QName qname = new QName(fgNamespace, fgLocalPart); OMElement element = serviceClient.invokeBlocking(qname, new Object[]{"1","1","lwj",xml}); String retResult = element.getFirstElement().getText(); System.out.println(retResult); long endTime=System.currentTimeMillis(); System.out.println("请求耗时:"+(endTime-startTime) + "ms"); } }

 

posted on 2017-06-20 10:21  13rj1115  阅读(954)  评论(0编辑  收藏  举报

导航