如何从 gSoap 消息中删除 xsi:type 信息?

2024-02-19

我在 Windows 平台上工作,gSoap 工作正常,但它在肥皂消息中集成了复杂的类型定义。

如何从soap消息中删除这些复杂的类型定义

xsi:type="ns4:MYServerRequestDto"

xsi:type="ns4:MySettingDto"

如何重新生成 gsoap 文件,使其不包含类型信息?

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns5="http://schemas.datacontract.org/2004/07/System.IO" xmlns:ns6="http://schemas.datacontract.org/2004/07/System" xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:ns4="http://schemas.datacontract.org/2004/07/MYServer.Utils" xmlns:ns1="http://tempuri.org/" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:wsc="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <SOAP-ENV:Body>
    <ns1:Register>
      <ns1:request xsi:type="ns4:MYServerRequestDto">
        <ns4:SerialNumber>2</ns4:SerialNumber>
        <ns4:MySetting xsi:type="ns4:MySettingDto">
          <ns4:AVersion>2</ns4:AVersion>
          <ns4:BVersion>2</ns4:BVersion>
         </ns4:MYSetting>
        <ns4:IPAddress>192.168.1.199</ns4:IPAddress>
       </ns1:request>
    </ns1:Register>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如果您使用 gSOAP 工具生成的代理,则需要使用以下命令设置代理的输出模式SOAP_XML_NOTYPE flag.

可以通过两种方式完成:

  1. 在代理本身的 init 函数中的一处,但是每次生成代理时它都会被覆盖。

    void nsTestBindingProxy::nsTestBindingProxy_init(soap_mode imode, soap_mode omode) 
    {
        omode |= SOAP_XML_NOTYPE; //removes xsi:type
        soap_imode(this->soap, imode);
        soap_omode(this->soap, omode);
        soap_endpoint = NULL;
        ...
    }
    
  2. 每次通过调用soap_omode函数在代码中初始化代理之后

    nsTestBindingProxy proxy();
    soap_omode(proxy.soap, proxy.soap->omode | SOAP_XML_NOTYPE);
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 gSoap 消息中删除 xsi:type 信息? 的相关文章

随机推荐