开发者

PHP AND SOAP. Change envelope

开发者 https://www.devze.com 2022-12-22 22:32 出处:网络
It is many questions there about PHP and SOAP. But I am not found answer on my situation. So. I use PHP SoapClient and WSDL for it. Object sends this:

It is many questions there about PHP and SOAP. But I am not found answer on my situation.

So. I use PHP SoapClient and WSDL for it. Object sends this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas开发者_StackOverflow中文版.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.site.com"><SOAP-ENV:Body>

But I need this:

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

Question. How I can do this with standard PHP class SoapClient?

Thank you.


I search answer in php.net

<?php
class MSSoapClient extends SoapClient {

    function __doRequest($request, $location, $action, $version) {
        $namespace = "http://tempuri.com";

        $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$namespace.'"', $request, 1);
        $request = preg_replace('/<ns1:(\w+)/', '<$1', $request);
        $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$namespace.'"'), array('/', ''), $request);

        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
}

$client = new MSSoapClient(...);
?>

This code change Envelope in request. And need for ASP SOAP server.


Use SoapVar::typeNamespace for set your xmlns:xsi

something like this :

new SoapVar($data, SOAP_ENC_OBJECT, "Type", "http://www.w3.org/2001/XMLSchema");

source : https://www.php.net/manual/fr/soapvar.construct

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号