Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-Soap pass method parameters

Tags:

php

soap

I have relatively no experience with SOAP. Im trying to work with a webservice for a client using WSDL mode. I'm having trouble passing parameters with the method and getting them to come the parameters to show up in the request as needed. I'm using the standard php soap class.

I need my SOAP request to be structured like the following:

 <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hostserver/">
    <SOAP-ENV:Body>
        <ns1:DoLogin>
            <ns1:request>
                <ns1:Session>
                    <ns1:SessionId>00000000-0000-0000-0000-000000000000</ns1:SessionId>
                </ns1:Session>
                <ns1:UserCredential>
                    <ns1:UserName>username</ns1:UserName>
                    <ns1:Password>password</ns1:Password>
                    <ns1:ApplicationID>00000000-0000-0000-0000-000000000000</ns1:ApplicationID>
                    <ns1:ClientID>00000000-0000-0000-0000-000000000000</ns1:ClientID>
                    <ns1:ClientVersion>V1.0</ns1:ClientVersion>
                </ns1:UserCredential>
            </ns1:request>
        </ns1:DoLogin>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

In php I call the function like so:

$client->DoLogin($args);

And the request ends up like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hostserver/"><SOAP-ENV:Body><ns1:DoLogin/></SOAP-ENV:Body></SOAP-ENV:Envelope>

No matter how I pass the args (single varabiables, array, class object) I cant get the request to have the structure as that.

Can anyone help me? I'm sure its going to be something quite simple.

like image 217
Fabian Avatar asked May 01 '09 03:05

Fabian


2 Answers

While working on a slightly related problem today, I found that the following PHP produced the SOAP request shown below:

$sc = new SoapClient($url);
$params = array('step' => 'ShippingInfo', 'value' => "hello");
$result = $sc->__soapCall('runStep', array('parameters' => $params));
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
 <SOAP-ENV:Body>
  <ns1:runStep>
     <ns1:step>ShippingInfo</ns1:step>
     <ns1:value>hello</ns1:value>
  </ns1:runStep>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

One catch I found was that if the parameters ($params) I passed did not conform to what was specified in the WSDL file, the message that the SOAP client generated would look similar to what you complain of--a message with a body contains no data value. I wonder if your problem lies here.

Also, note how the above PHP uses two arrays to pass parameters. The first array contains the parameters and their names. The second contains the first array. Interesting syntax, I know. :-)

FYI, the example code above being used to communicate with a C# .Net WCF service having the following contract:

[OperationContract]
string runStep(string step, string value);
like image 193
Ben Gribaudo Avatar answered Sep 22 '22 02:09

Ben Gribaudo


try this:

$soapClient->__soapCall('methodToCall', array('parameters' => $yourParamsArray));

That worked for me with a .NET webservice.

like image 32
bgondy Avatar answered Sep 19 '22 02:09

bgondy