【问题标题】:Setting SOAP Version with node-soap.使用 node-soap 设置 SOAP 版本。
【发布时间】:2014-07-24 13:23:04
【问题描述】:

我正在使用这个 npm 模块:https://github.com/vpulim/node-soap

我想使用的 Web 服务仅使用 SOAP 1.2,并在使用任何其他 SOAP 版本时返回服务器错误。

是否有人遇到过同样的问题并且知道如何设置 SOAP 版本?

【问题讨论】:

    标签: node.js soap


    【解决方案1】:

    使用最新版本的https://github.com/vpulim/node-soap,可以选择设置 SOAP 1.2 标头

    var options = {
        forceSoap12Headers: true
    };
    soap.createClient(url,options, function (err, client) {
        //Your soap call here
    }); 
    

    IMO,我认为我们不应该修改 lib,不利于升级

    【讨论】:

      【解决方案2】:

      我已经解决了 NicolasZ 所说的问题,我当前的 soap/lib/client.js 是:

      第 187 行:

       xml = "<soap:Envelope " +
      //"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
      "xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" " +
      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
      encoding +
      this.wsdl.xmlnsInEnvelope + '>' +
      ((self.soapHeaders || self.security) ?
        (
          "<soap:Header>" +
          (self.soapHeaders ? self.soapHeaders.join("\n") : "") +
          (self.security ? self.security.toXML() : "") +
          "</soap:Header>"
        )
        :
          ''
        ) +
      "<soap:Body" +
      (self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
      ">" +
      message +
      "</soap:Body>" +
      "</soap:Envelope>";
      

      【讨论】:

        【解决方案3】:

        您可以进入soap\lib\client.js 到第186 行并修改信封语法,使其与soap 1.2 兼容:

         //modify this with the envelope used by soap1.2:
        xml = "<soap:Envelope " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
            'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
            'xmlns:ns2="http://xml.apache.org/xml-soap"' +
            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            encoding +
            this.wsdl.xmlnsInEnvelope + '>' +
            //until here
            ((self.soapHeaders || self.security) ?
              (
                "<soap:Header>" +
                (self.soapHeaders ? self.soapHeaders.join("\n") : "") +
                (self.security ? self.security.toXML() : "") +
                "</soap:Header>"
              )
              :
                ''
              ) +
            "<soap:Body" +
            (self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
            ">" +
            message +
            "</soap:Body>" +
            "</soap:Envelope>";
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-07-23
          • 1970-01-01
          • 2014-11-05
          相关资源
          最近更新 更多