【问题标题】:SOAP set proper xmlns headersSOAP 设置正确的 xmlns 标头
【发布时间】:2013-06-14 17:56:50
【问题描述】:

我在设置 SOAP 标头时遇到了两个问题。首先,我以前从未这样做过,两次,我似乎无法在这里找到一个好的解决方案。如果有完全相同的重复,我深表歉意,如果有,请指出正确的方向。

我需要在soap:Envelope 上设置以下xmlns:xsi 和xmlns:xsd 数据集。我还需要在 XML 中的第一个标记上设置一个 xmlns 属性(粗略示例)。

需要添加第一部分,当我执行 __getLastRequest() 时,第二部分已经存在。并且需要添加第三部分(只是 SendPurchases xmlns 属性)。

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


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
xmlns:ns1="urn:[taken out for security purposes]">


<soap:Body>
    <SendPurchases xmlns="urn:...">
    </SendPurchases>
</soap:Body>

我需要为此使用 header() 吗? 我正在使用 PHP 的 SOAP 客户端。非常感谢任何帮助!

编辑:

我选择了另一条路线,不过还是感谢您的所有回答!

【问题讨论】:

  • 您确定 SOAP 标头是您在这里使用的正确术语吗?
  • 我不明白这个问题。设置soap 服务时,它会为您创建一个WSDL。不需要自己做..
  • 你能贴出你用来发出肥皂请求的代码吗?
  • 我需要能够将 xmlns:xsi 和 xmlns:xsd“属性”添加到 soap:Envelope。我还需要能够在 SendPurchases 节点上添加 xmlns="urn:..." "attribute"。请求是 $this->soap->SendPurchases($object);
  • 有人吗?非常感谢任何帮助。

标签: php xml soap


【解决方案1】:

我的信封也有类似的问题,我对此进行了修复。我将使用您提供的数据发布修复程序,您必须检查是否一切正常:

编辑请求的自定义类:

class CustomSoapClient extends SoapClient {

                            function __doRequest($request, $location, $action, $version) {

                                $request = str_replace('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">', '', $request);
                                // parent call
                                return parent::__doRequest($request, $location, $action, $version);
                            }

                        }

设置soap客户端:

$client = new CustomSoapClient($wsdl, array(
                                'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
                                'exceptions' => true,
                                'trace' => 1,
                                'soap_version' => SOAP_1_2,
                                ));

请求:

//notice that the envelope is in the request! also you need to change the urn
$request = '
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/xmlns:ns1="urn:[taken out for security purposes]">


<soap:Body>
   <SendPurchases xmlns="urn:...">
   </SendPurchases>
</soap:Body>
</SOAP-ENV:Envelope>';

$xmlvar = new SoapVar($request, XSD_ANYXML);

$result = $client->Controleer($xmlvar);

print_r($result); // finally check the result

希望对你有帮助:)

【讨论】:

    【解决方案2】:

    可以在此处找到使用 PHP 的 SoapClient 正确实现的详细示例:http://www.php.net/manual/en/soapclient.soapclient.php#97273

    【讨论】:

    • 我无法使用这些步骤。我的 SOAP 请求仍然没有设置 xmlns。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 2020-09-28
    • 1970-01-01
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多