将属性传递给Soap Header

时间:2019-01-04 07:23:16

标签: php soap soap-client

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

<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 scrip

$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。

现在从事这项工作已有几天,并且在线阅读了大量文章-仍然没有。任何帮助都将得到高度重视。

0 个答案:

没有答案