0

I got this problem when I'm trying to call a WCF method from php. It just shows 500 error when I send the request.

        $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;
        }

So I tried to check its XML by Wireshark, the XML is like this:

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

But the fine XML should be like this:

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

So the question comes: How can I customize the header in phpsoap?

PolarStar
  • 1
  • 1
  • Does this answer your question? [How to set this php soap header?](https://stackoverflow.com/questions/7145143/how-to-set-this-php-soap-header) – Cray Mar 28 '20 at 15:25

1 Answers1

0

There are many examples in the official documentation.

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

$client->__setSoapHeaders($header);

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

Result.
enter image description here
Here are some useful links.
https://www.php.net/manual/en/class.soapheader.php
https://www.php.net/manual/en/soapclient.setsoapheaders.php

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22