Я пытаюсь отправить / получить SOAP-запрос, используя SOAPConnectionFactory.Мне нужно отправить запрос тела, как показано ниже,
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="http://apiDoc.com/integration/">
<soap:Header>
<int:Options>
<int:ICD>false</int:ICD>
<int:UpdateLastModified>true</int:UpdateLastModified>
</int:Options>
</soap:Header>
<soap:Body>
<int:LogIn>
<int:username>AAA</int:username>
<int:password>pasword</int:password>
</int:LogIn>
</soap:Body>
</soap:Envelope>
Код, который я пробовал:
try {
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
MessageFactory mf = MessageFactory.newInstance();
String soapRequestXml ="pasting the request body here ";
SOAPMessage sm = mf.createMessage(new MimeHeaders(),
new ByteArrayInputStream(soapRequestXml.getBytes()));
sm.setProperty("Content-Type", "application/soap+xml");
sm.saveChanges();
QName bodyName = new QName("Response");
URL endpoint = new URL("http://MyIP/wsdk/service.asmx");
SOAPMessage response = connection.call(sm, endpoint);
System.out.println((response.getSOAPBody()));
SOAPBody sb = response.getSOAPBody();
Iterator iterator = sb.getChildElements(bodyName);
while (iterator.hasNext()) {
SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
String val = bodyElement.getValue();
System.out.println("I want to print each element's value like Id,TypeId,Success" + val);
}
} catch (Exception ex) {
ex.printStackTrace();
}
OP is:
[soap:Body: null]
Фактический ОП получает ПОСТМАНА:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Response xmlns="http://intergratedservice.com/integration/">
<Result xsi:type="LoginResponse">
<Id>1402</Id>
<TypeId>1</TypeId>
<Success>true</Success>
</Result>
</Response>
</soap:Body>
</soap:Envelope>
Кто-то скажет мне, где я делаю ошибку?