在调用webservice时,出现如下错误信息:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:Websevice2.site
org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.prochanges.services.register.RegisterService.setCallBackAddr1(RegisterService.java:31)
at com.prochanges.services.register.RegisterService.main(RegisterService.java:72)
实现代码:
public String setCallBackAddr() { try { String url = "http://192.168.0.27:7777/axis2/services/SMSService?wsdl"; String uc = "18926380454"; String oldpw = "Yj123456"; String rand = getRandom1(); String pw = MD5Encode(rand.concat(oldpw).concat(oldpw)); Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(endpoint)); call.setOperationName("setCallBackAddr"); // 调用的方法名 call.setReturnType(XMLType.XSD_STRING); // 返回值类型 call.addParameter("uc", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); call.addParameter("pw", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); call.addParameter("rand",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); call.addParameter("url", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN); Object[] o = {uc, pw, rand, url}; String connID = (String)call.invoke(o); System.out.println("connID: " + connID); return connID; } catch (Exception e) { e.printStackTrace(); } return null; }
问题原因:
注意参数部分,e.g.
错误方式:
call.addParameter(uc, org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
正确方式:需要对参数uc加上双引号
call.addParameter("uc", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
WSDL文件描述:
<wsdl:message name="setCallBackAddrRequest"> <wsdl:part name="uc" type="xsd:string"></wsdl:part> <wsdl:part name="pw" type="xsd:string"></wsdl:part> <wsdl:part name="rand" type="xsd:string"></wsdl:part> <wsdl:part name="url" type="xsd:string"></wsdl:part> </wsdl:message>