在java中使用Xml文档创建Soap请求

时间:2014-02-28 06:53:25

标签: java xml soap

我需要提出这个肥皂请求

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Update xmlns="http://tempuri.org/">
      <doc>xml</doc>
    </Update>
  </soap:Body>
</soap:Envelope>

在那个<doc>xml</doc>这是我必须添加Xml文档文件的字段,但它始终获得String formate。所以如何让这个Soap请求可以让任何人给我一些想法。

我已尝试过CDATA,但另一方面在提出请求时给出错误。

        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://tempuri.org/";
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("tem", serverURI);
        SOAPElement sOAPElement = envelope.addChildElement("Update", "tem");

        SOAPElement xml_APElement = sOAPElement.addChildElement("doc", "tem");
        CDATASection aSection = soapPart.createCDATASection(builder.toString());
        xml_APElement.appendChild(aSection);




        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI + "Update");

        soapMessage.saveChanges();
        System.out.print("Request SOAP Message = ");
        soapMessage.writeTo(System.out);

0 个答案:

没有答案