java调用webservice代码片段
StreamSource xmlSource = new StreamSource(new StringReader(soapBody));
URL wsdlURL = new URL(wsdlUrl);
QName serviceQName = new QName(targetNamespace, serviceName);
Service service = Service.create(wsdlURL, serviceQName);
//创建port端口及 Dispatch<Source>对像
QName portQName = new QName(targetNamespace, portName);
Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source orderSource = dispatch.invoke(xmlSource);
走到这一步
Source orderSource = dispatch.invoke(xmlSource);
报错:
javax.xml.ws.WebServiceException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,57]
Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#ElementPrefixUnbound?soapenv&soapenv:Envelope
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.message.impl.MessageImpl.getAsSOAPMessage(MessageImpl.java:328)
at org.apache.axis2.jaxws.client.dispatch.BaseDispatch.getBodyElementQNameFromDispatchMessage(BaseDispatch.java:403)
at org.apache.axis2.jaxws.client.dispatch.BaseDispatch.getOperationDescriptionForDispatch(BaseDispatch.java:266)
at org.apache.axis2.jaxws.client.dispatch.BaseDispatch.invoke(BaseDispatch.java:189)
at cn.linkey.rulelib.S017.R_S017_B001.run(R_S017_B001.java:67)
at cn.linkey.rule.ExecuteEngine.run(ExecuteEngine.java:34)
at cn.linkey.rule.ExecuteEngine.run(ExecuteEngine.java:49)
at cn.linkey.servlet.Action.run(Action.java:165)
at cn.linkey.servlet.Action.doGet(Action.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
不知道什么原因,用TEST跑这段代码没问题