我必须用 SOAP 调用 Web 服务。我用 Java 制作了一个客户端,它产生以下 SOAPMessage:
<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:abc="http://company.com/SAMPLE/ABC">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<abc:genXX>
<ServiceRequestID>111</ServiceRequestID>
<Code>328630962</Code>
</abc:genXX>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
当我在应用程序中调用它时,该调用会在解析 SOAP 期间产生错误:
<SOAP:Header>
</SOAP:Header>
<SOAP:Body>
<SOAP:Fault xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>SOAP:Client</faultcode>
<faultstring>Error during parsing of SOAP header</faultstring>
<faultactor>http://sap.com/xi/XI/Message/30</faultactor>
<detail>
<SAP:Error SOAP:mustUnderstand="1"
xmlns:SAP="http://sap.com/xi/XI/Message/30">
<SAP:Category>XIProtocol</SAP:Category>
<SAP:Code area="PARSER" />
<SAP:P1 />
<SAP:P2 />
<SAP:P3 />
<SAP:P4 />
<SAP:AdditionalText />
<SAP:Stack>System error in parser
</SAP:Stack>
</SAP:Error>
</detail>
</SOAP:Fault>
</SOAP:Body>
</SOAP:Envelope>
但是,当我使用具有 SOAP UI 的同一台计算机调用它时,Web 服务响应良好。我的应用程序中的客户端是这样制作的:
public void callWebservice(String serviceRequestID, String code) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
URLEndpoint url = new URLEndpoint ("http://company.com:50000/");
SOAPMessage soapResponse = soapConnection.call(
createSOAPRequest(serviceRequestID, code), url);
{...}
soapConnection.close();
} catch (Exception e) {
//
}
private SOAPMessage createSOAPRequest(String serviceRequestID,
String code) throws SOAPException{
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://company.com/SAMPLE/ABC";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("abc", serverURI);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("genXXX", "abc");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ServiceRequestID");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("Code");
soapBodyElem1.addTextNode(serviceRequestID);
soapBodyElem2.addTextNode(code);
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI );
String loginPassword = "USER:PASSWORD";
headers.addHeader("Authorization", "Basic " + new
String(Base64.encodeBase64(loginPassword.getBytes())));
soapMessage.saveChanges();
return soapMessage;
}
}
我检查了标题和身份验证,这是正确的。如果我更改用户或密码,Webservice 会使用 401 Unauthorized 响应,所以我认为标头已按预期发送。
您对导致我的应用程序内部错误的原因有任何线索吗?