首页 > 解决方案 > 将属性传递给soap Header

问题描述

我正在尝试在肥皂请求下重新创建

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://test.gbd.chdb.test.net">
       <soapenv:Header>
          <userId>5647775-b7d7-4a45-9570-654116547654</userId>
       </soapenv:Header>
       <soapenv:Body>
          <data:getPerson>
             <!--Optional:-->
             <iin>700521700054</iin>
             <!--Optional:-->
             <consentConfirmed>true</consentConfirmed>
          </data:getPerson>
       </soapenv:Body>
    </soapenv:Envelope>

使用下面的 php 脚本

$opts = array(some attributes);

        $soap_client = new \SoapClient(null,
                                array(
                                    'location' => 'https://test.test.net/testServices/PersonDetailsImplService',
                                    'uri' => 'http://test.gbd.chdb.test.net',
                                    'login'    => 'XXXXXXX',
                                    'password' => 'YYYYYYY',
                                    'cache_wsdl' => WSDL_CACHE_NONE,
                                    'soap_version'=> SOAP_1_1,
                                    'style' => SOAP_RPC,
                                    'use' => SOAP_ENCODED,
                                    'trace'          => true,
                                    'exceptions'     => true,
                                    'stream_context' => stream_context_create($opts)
                                )
                            );
        $auth = new \stdClass();
            $auth->userId = '5647775-b7d7-4a45-9570-654116547654';
        $header = new \SoapHeader('http://test.gbd.chdb.test.net', 'Header', $auth);

        $soap_client->__setSoapHeaders($header);
        $result = $soap_client->getPerson();

每次执行此操作时,我都会收到响应“userId 字段丢失”。不确定我做错了什么,因为我在下面的脚本中设置 Header 属性并通过 __setSoapHeaders 将标题设置为我的 SoapClient。

几天来一直在研究它,并在网上浏览了大量文章 - 仍然没有成功。任何帮助都将受到高度重视。

标签: phpsoapsoap-client

解决方案


推荐阅读