在 Web 服务请求中将字符串内容编码为 XML

发布于 2024-11-29 20:25:38 字数 1231 浏览 0 评论 0原文

我正在处理一个问题,必须使用从 WSDL 开发的遗留 Web 服务客户端,该客户端将实际的 XML 请求作为请求中唯一一个变量的值传递。我现在使用的 Web 服务具有不同的 WSDL,我试图欺骗我的 XML 解析器,但它正在对我的实际 XML 响应进行编码。

无论如何,是否可以配置解析器,以便将请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <request>&lt;elemA&gt;&lt;elemB&gt;abc&lt;/elemB&gt;&lt;/elemA&gt;</request>
   </soapenv:Body>
</soapenv:Envelope>

更改为:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <foo>
         <elemA>
            <elemB>abc</elemB>
         </elemA>
      </foo>
   </soapenv:Body>
</soapenv:Envelope>

我正在使用 JAX-WS 和 WebSphere 7。

提前致谢。

巴勃罗

I am dealing with a problem where I must use a legacy web services client developed from a WSDL that passes in the actual XML request as the value of the only one variable in the request. The web service that I am consuming now has a different WSDL and I am trying to trick my XML parser however it is encoding my actual XML response.

Is there anyway to configure the parser so the request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <request><elemA><elemB>abc</elemB></elemA></request>
   </soapenv:Body>
</soapenv:Envelope>

is changed into this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <foo>
         <elemA>
            <elemB>abc</elemB>
         </elemA>
      </foo>
   </soapenv:Body>
</soapenv:Envelope>

I am using JAX-WS and WebSphere 7.

Thanks in advance.

Pablo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2024-12-06 20:25:38

去年我曾经处理过这种情况,我的解决方案是将肥皂消息中的 XML 包装在 CDATA 部分中。

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Header/>
       <soapenv:Body>
          <![CDATA[
          <foo>
             <elemA>
                <elemB>abc</elemB>
             </elemA>
          </foo>
          ]]
       </soapenv:Body>
    </soapenv:Envelope>

I had to deal with this situation once last year, the solution for me was to wrap the XML that was going inside the soap message inside a CDATA section.

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Header/>
       <soapenv:Body>
          <![CDATA[
          <foo>
             <elemA>
                <elemB>abc</elemB>
             </elemA>
          </foo>
          ]]
       </soapenv:Body>
    </soapenv:Envelope>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文