【问题标题】:PHP AND SOAP. Change envelopePHP 和 SOAP。更换信封
【发布时间】:2010-03-16 18:11:14
【问题描述】:

那里有很多关于 PHP 和 SOAP 的问题。但我没有找到关于我的情况的答案。

所以。我为此使用 PHP SoapClient 和 WSDL。对象发送这个:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.site.com"><SOAP-ENV:Body>

但我需要这个:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>

问题。如何使用标准的 PHP 类 SoapClient 做到这一点?

谢谢。

【问题讨论】:

  • 我认为这意味着您的 WSDL 不正确?您是否也创建了 SOAP 服务器部分?
  • 不,WSDL 是正确的,因为其他库(C# 的 ActiveX 控件)可以很好地使用它并发送真正的命名空间。我无法更改 SOAP 服务器。我需要使用它来访问服务功能。
  • 如果您认为这会导致与您的 SOAP 服务通信时出现问题,那么这可能是一个错误的假设。您的错误可能与您的消息中缺少属性有关,就像我刚刚发生的那样。

标签: php soap envelope


【解决方案1】:

我在 php.net 中搜索答案

<?php
class MSSoapClient extends SoapClient {

    function __doRequest($request, $location, $action, $version) {
        $namespace = "http://tempuri.com";

        $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$namespace.'"', $request, 1);
        $request = preg_replace('/<ns1:(\w+)/', '<$1', $request);
        $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$namespace.'"'), array('/', ''), $request);

        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
}

$client = new MSSoapClient(...);
?>

此代码更改请求中的信封。并且需要 ASP SOAP 服务器。

【讨论】:

    【解决方案2】:

    使用SoapVar::typeNamespace 设置您的xmlns:xsi

    类似这样的:

    new SoapVar($data, SOAP_ENC_OBJECT, "Type", "http://www.w3.org/2001/XMLSchema");
    

    来源:https://www.php.net/manual/fr/soapvar.construct

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多