package inter.webservice;
import java.util.Map;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.dom4j.DocumentException;
import com.framework.util.XMLUtil;
public class V {
public static void main(String[] args) {
String url = "http://localhost:8080/bdg/services/serviceForLis?wsdl";
RPCServiceClient serviceClient;
try {
serviceClient = new RPCServiceClient();
// 指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(url);
Options options = serviceClient.getOptions();
//确定目标服务地址
options.setTo(targetEPR);
//确定调用方法
options.setAction("synchroCollectfees");
QName qname = new QName("http://webservice.inter", "synchroCollectfees");
// 指定getPrice方法的参数值
String data = "<Request>"
+ "<PeMasterId>1157747</PeMasterId>"
+ "<List>"
+ "<ItemGroupId>11289571</ItemGroupId>"
+ "</List>"
+ "</Request>";
Object[] parameters = new Object[] { data };
// 调用方法一 传递参数,调用服务,获取服务返回结果集
OMElement element = serviceClient.invokeBlocking(qname, parameters);
//值得注意的是,返回结果就是一段由OMElement对象封装的xml字符串。
System.out.println("返回的string的xml"+element.toString());
Map map = XMLUtil.Dom2Map(element.toString());
String s = (String) map.get("return");
Map m = XMLUtil.Dom2Map(s);
System.out.println(m);
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
参考链接:https://blog.csdn.net/weixin_37610156/article/details/79074499