2015-02-19 2 views
1

Это то, что мой код создает:запроса неправильно 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; 
    } 

Помогите: что я делаю неправильно?

ответ

4

В моем soapenv: Конверт || xmlns: soapenv идет дважды

Он не появляется дважды. Вы определяете 2 префикса, привязанных к одному и тому же пространству имен.


XMLNS: soapenv = "http://schemas.xmlsoap.org/soap/envelope/"

Xmlns: SOAP-ENV = "HTTP: // схемы. xmlsoap.org/soap/envelope/»


Пожалуйста, помогите: что я делаю неправильно ?

Ничего. Не имеет значения, является ли префикс пространства имен soapenv или SOAP-ENV или polar-bear-ninjas. Пока префикс привязан к пространству имен, вы полностью квалифицируете этот элемент XML. Оба XML являются действительными, и не имеет значения, какой префикс используется.

+0

Верно, это похоже на определение переменной. Тогда вы можете использовать его или нет. Является избыточным, но XML действителен. – Victor

+0

Большое спасибо. Здесь у меня есть еще одно сомнение: я хочу, чтобы ti удалял ** standalone = "no" ** из ** **, или должен Я задаю другой вопрос для этого сомнения? –

+0

Это довольно странно. Вы имеете в виду DTD где-то в документе или в коде, который должен обрабатывать этот XML? Вот где автономный становится полезным. Создайте еще один вопрос и заполните детали там, так как нам нужно задать вам пару вопросов, чтобы получить ответ. –

Смежные вопросы