Это то, что мой код создает:запроса неправильно SOAP получения создан
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>
В моем soapenv: Envelope || XMLNS: soapenv приходит дважды
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
Теперь это то, что мне нужно: здесь xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
нет в запросе SOAP
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:ws="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<ws:isUserExists>
<userId>10</userId>
</ws:isUserExists>
</soapenv:Body>
</soapenv:Envelope>
Java-кода, который я использую для создания запроса is:
public static SOAPMessage createIsUserExistsSOAPRequest(User user) throws SOAPException
{
MessageFactory messageFactory =MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
soapMessage.getSOAPHeader().setPrefix("soapenv");
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.setPrefix("soapenv");
envelope.addNamespaceDeclaration("ws","http://example.com");
// SOAP Body
SOAPBody soapBody = envelope.getBody();
soapBody.setPrefix("soapenv");
SOAPElement ensureUserExistsElem = soapBody.addChildElement("isUserExists", "ws");
SOAPElement userIdElem = ensureUserExistsElem.addChildElement("userId");
userIdElem.addTextNode(user.userId);
String authorization = new sun.misc.BASE64Encoder().encode(("[email protected]").getBytes());
MimeHeaders hd = soapMessage.getMimeHeaders();
hd.addHeader("Authorization", "Basic " + authorization);
soapMessage.saveChanges();
return soapMessage;
}
Помогите: что я делаю неправильно?
Верно, это похоже на определение переменной. Тогда вы можете использовать его или нет. Является избыточным, но XML действителен. – Victor
Большое спасибо. Здесь у меня есть еще одно сомнение: я хочу, чтобы ti удалял ** standalone = "no" ** из ** Xml version = "1.0" encoding = "UTF-8" standalone = "no"?> **, или должен Я задаю другой вопрос для этого сомнения? –
Это довольно странно. Вы имеете в виду DTD где-то в документе или в коде, который должен обрабатывать этот XML? Вот где автономный становится полезным. Создайте еще один вопрос и заполните детали там, так как нам нужно задать вам пару вопросов, чтобы получить ответ. –