Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP AND SOAP. Change envelope

Tags:

php

soap

envelope

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

like image 266
Oleg Avatar asked Mar 16 '10 18:03

Oleg


People also ask

What is SOAP ENV envelope?

The SOAP envelope indicates the start and the end of the message so that the receiver knows when an entire message has been received. The SOAP envelope solves the problem of knowing when you are done receiving a message and are ready to process it. The SOAP envelope is therefore basically a packaging mechanism.

How can make SOAP call in PHP?

To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.

What is SOAP protocol in PHP?

SOAP stands for Simple Object Access Protocol. SOAP is an application communication protocol. SOAP is a format for sending and receiving messages. SOAP is platform independent. SOAP is based on XML.

What is SOAP envelope namespace?

SOAP defines two namespaces: The SOAP envelope, the root element of a SOAP message, has the following namespace identifier: "http://schemas.xmlsoap.org/soap/envelope" The SOAP serialization, the URI defining SOAP's serialization rules, has the following namespace identifier: "http://schemas.xmlsoap.org/soap/encoding"


1 Answers

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.

like image 195
Oleg Avatar answered Sep 17 '22 09:09

Oleg