如何在php中自定义soap标头

问题描述 投票:0回答:1

当我尝试从php调用WCF方法时遇到了这个问题。发送请求时,它仅显示500错误。

        $wsdl = "http://localhost:12019/XianglanCommuService/?wsdl";
        $soapClient = new SoapClient($wsdl, array('soap_version' => SOAP_1_2));
        try {
            return $soapClient->Test();
        } catch (SoapFault $fault) {
            return $fault->faultstring;
        }

所以我尝试通过Wireshark检查其XML,XML如下所示:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/">
    <env:Body>
        <ns1:Test/>
    </env:Body>
</env:Envelope>

但是好的XML应该是这样的:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/">
    <env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsa:Action>
            http://tempuri.org/IWCFService/Test
        </wsa:Action>
    </env:Header>
    <env:Body>
        <ns1:Test/>
    </env:Body>
</env:Envelope>

所以问题来了:如何在phpsoap中自定义标题?

php wcf soap-client
1个回答
0
投票

官方文档中有很多示例。

$header = new SoapHeader('', 
                            'Action',
                            ' http://tempuri.org/IWCFService/Test');

$client->__setSoapHeaders($header);

$client->__soapCall("Test", null);

结果。enter image description here这里是一些有用的链接。https://www.php.net/manual/en/class.soapheader.phphttps://www.php.net/manual/en/soapclient.setsoapheaders.php

© www.soinside.com 2019 - 2024. All rights reserved.