비누 클라이언트의 자식 요소에 접두사를 추가하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com//questions/25049734

  •  21-12-2019
  •  | 
  •  

문제

요청 메시지를 보내려면 SOAP 클라이언트를 작성하여 요청을 성공적으로 보낼 수 있지만 메시지를 수정해야합니다. 메시지를 수정해야합니다. 필요한 수정은 자식 요소에 접두사를 추가하는 것입니다. 일단 다음 코드를 사용했지만 아무 일도 일어나지 않습니다.

WebsiteConfigID.addNamespaceDeclaration("v3", "http://tnwebservices.ticketnetwork.com/tnwebservice/v3.2");
.

전류 출력

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
              xmlns:v3="http://tnwebservices.ticketnetwork.com/tnwebservice/v3.2">
   <env:Header/>
   <env:Body>
       <GetEvents>
          <websiteConfigID>1111</websiteConfigID>
          <cityZip>Paris</cityZip>
       </GetEvents>
   </env:Body>
</env:Envelope>
.

예상 출력

 <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
              xmlns:v3="http://tnwebservices.ticketnetwork.com/tnwebservice/v3.2">
   <env:Header/>
   <env:Body>
       <v3:GetEvents>     <<prefix is added
          <v3:websiteConfigID>1111</v3:websiteConfigID>  <<prefix is added
          <v3:cityZip>Paris</v3:cityZip>  <<prefix is added
       </v3:GetEvents>  
   </env:Body>
 </env:Envelope>
.

코드

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();

    SOAPConnection connection = soapConnectionFactory.createConnection();

    SOAPMessage message = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();



    SOAPBody body = message.getSOAPBody();
    SOAPPart part = message.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    envelope.addNamespaceDeclaration("v3", "http://tnwebservices.ticketnetwork.com/tnwebservice/v3.2");
    SOAPFactory soapFactory = SOAPFactory.newInstance();

    Name bodyName;
    bodyName = soapFactory.createName("GetEvents");

    SOAPBodyElement getEvents = body.addBodyElement(bodyName);
    Name childName = soapFactory.createName("websiteConfigID");
    SOAPElement WebsiteConfigID = getEvents.addChildElement(childName);
    WebsiteConfigID.addTextNode("1111");

    childName = soapFactory.createName("cityZip");
    SOAPElement CityZip = getEvents.addChildElement(childName);
    CityZip.addTextNode("Paris");

    message.writeTo(System.out);
.

도움이 되었습니까?

해결책

SOAPFactory 또는 접두사 및 URI 정보를 취하는 QName 메소드를 사용하십시오.예를 들어, bodyName = soapFactory.createName("GetEvents");를 호출하는 대신

여야합니다.
bodyName = soapFactory.createName("GetEvents", "v3",
   "http://tnwebservices.ticketnetwork.com/tnwebservice/v3.2");
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top