24,923
社区成员
发帖
与我相关
我的任务
分享
String relationXML="<input>" +
"<dicname>DicAreaApp</dicname>"+
"<itemid>0</itemid>"+
"</input>";
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress("http://cqdfjy.cfq.hrssdd/cqhrweb/services/ServieAnt");
call.setOperationName(new QName("http://cqdfjy.cfq.hrssdd/cqhrweb/services/ServieAnt","getDic"));
//添加请求头
SOAPHeaderElement cpHeader = new SOAPHeaderElement("http://schemas.xmlsoap.org/soap/envelope/","soap:Head");
try {
//用户名
SOAPElement userName = cpHeader.addChildElement("username");
userName.addTextNode("dvetpr");
//密码
SOAPElement password = cpHeader.addChildElement("password");
password.addTextNode("1rgr2e1");
// 设定 Header
call.addHeader(cpHeader);
} catch (SOAPException e) {
e.printStackTrace();
}
String result = (String) call.invoke(new Object[] {relationXML});
System.out.println(result);
<soapenv:Head>
<username>dvetpr</username>
<password>1rgr2e1</password>
</soapenv:Header>
<soapenv:Body>
<input>
<dicname>DicAreaApp</ dicname >
<itemid>0</itemid>
</input>
</soapenv:Body>
response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXParseException: 不允许处理指令目标匹配“[xX][mM][lL]”。</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">app-2</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
不知道为什么会这样。Axis的Call调用和HttpClient调用应该还是有一定而区别的。