WebService客户端调用不写javabean直接用String的方法
1、Axis1.4 传输用SOAPBodyElement解析用Vector
参考url:http://www.blogjava.net/robin/archive/2006/01/02/26385.html
Service service = new Service(); Call call = new Call(service);String endpoint = "http://127.0.0.1:80/XXXX/services/HelloService";call.setTargetEndpointAddress(new java.net.URL(endpoint));String namespace = "http://xxx.xxxx.com/webservice";String method = "methodA";call.setSOAPActionURI(method);call.setOperationName(method);call.setProperty(Call.OPERATION_STYLE_PROPERTY, Style.DOCUMENT.getName());call.setPortName(new QName(namespace, "HelloServicePort"));call.setPortTypeName(new QName(namespace, "HelloServicePortType"));InputStream in = new ByteArrayInputStream(aaa.getBytes());Object[] obj = new Object[] { new SOAPBodyElement(in) };Vector result = (Vector)call.invoke(obj);SOAPBodyElement element = (SOAPBodyElement) result.get(0);String reqXml="<?xml version="1.0" encoding="UTF-8"?>XXXXX";String xmlNamespace = "http://xxx.xxxx.com/webservice";String xmlMethod = "methodA";String xmlHead = "methodARequest";String intUrl = "http://127.0.0.1:80/xxxxxx/services/HelloService";String encoding = "UTF-8"; EndpointReference targetEPR = new EndpointReference(intUrl);OMFactory fac = OMAbstractFactory.getOMFactory();//前缀prefix必须设置空串OMNamespace ns = fac.createOMNamespace(xmlNamespace, "");//请求对象OMElement requestElement = fac.createOMElement(xmlHead, ns);//报文OMElement value = toOMElement(reqXml, encoding);requestElement.addChild(value); Options options = new Options();ServiceClient client = new ServiceClient();//options.setTimeOutInMilliSeconds(60000L);options.setTo(targetEPR);options.setAction(xmlMethod);client.setOptions(options); //调用服务端OMElement result = client.sendReceive(requestElement);//这个result带命名空间,但不带xml声明System.out.println("result : " + result.toString());public static OMElement toOMElement(String xmlStr, String encoding) {OMElement xmlValue;try { xmlValue = new StAXOMBuilder(new ByteArrayInputStream(xmlStr .getBytes(encoding))).getDocumentElement(); return xmlValue;}catch (Exception e) { return null;}}