drno-reg
@drno-reg
см не кратко

Почему не транслируются значения атрибутов в SOAP запрос?

Здравствуйте.

У меня есть пример SOAP запроса

<?xml version="1.0" encoding="UTF-8" ?>
         <SOAP:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <SOAP:Body>
         <GetParameter xmlns="http://examples/2001">
		 <request>
         <MonCode xmlns="http://newsite/mon">Latency</MonCode>
		 <TimeFrom xmlns="http://newsite/mon">2016-10-26T11:00</TimeFrom>
		 <TimeTo xmlns="http://newsite/mon">2016-10-26T12:00</TimeTo>
         </request>
		 </GetParameter>
         </SOAP:Body>
         </SOAP:Envelope>


Формирую SOAP запрос на JAVA, использую SAAJ API

следующий код

MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
    envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    envelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelop/");

    SOAPBody body = message.getSOAPBody();
    SOAPElement bodyElement = body.addChildElement("GetParameter");
    bodyElement.setAttribute("xmlns", "http://examples/2001");
    bodyElement = body.addChildElement("request");
    SOAPElement paramsElement = bodyElement.addChildElement("MonCode");
    paramsElement.setAttribute("xmlns", "http://newsite/mon");
    paramsElement.addTextNode("Latency");
    paramsElement = bodyElement.addChildElement("TimeFrom");
    paramsElement.setAttribute("xmlns", "http://newsite/mon");
    paramsElement.addTextNode("2016-10-26T11:00");
    paramsElement = bodyElement.addChildElement("TimeTo");
    paramsElement.setAttribute("xmlns", "http://newsite/mon");
    paramsElement.addTextNode("2016-10-26T12:00");


в результате получаю такой SOAP запрос

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelop/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <GetParameter xmlns=""/>
    <request>
      <MonCode xmlns="">Latency</MonCode>
      <TimeFrom xmlns="">2016-10-26T11:00</TimeFrom>
      <TimeTo xmlns="">2016-10-26T12:00</TimeTo>
    </request>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Все хорошо, НО куда-то деваются значения атирибутов "examples/2001" "newsite/mon".

В чем моя ошибка и как решить эту проблему?
  • Вопрос задан
  • 138 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы