8

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.

0

5 Answers 5

17

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry for commenting an old thread, but this casting $params as an array when making the function call worked for me. Thanks Ben.
Actually you can just pass an array of array: array($params) and it will work the same.
You saved my life right now Ben Gribaudo :) $sc->FuncName(array("param" => "value)) is passing parameters as expected but $sc->__soapCall("FuncName", array("param" => "value") is not passing any parameter. Put parameters into array("parameters" => $parameters) did the trick. Thanks a lot dude.
3

try this:

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

That worked for me with a .NET webservice.

Comments

1
This is valid way: right mr.bgondy
$result = $soapClient->methodsomefunction("params1"=>"value","params2"=>"value2");

my question is that you said

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

above code for .net web services but when i have tried this method for .net asp web services, parameters values not parse i think so because when i removed params=value not effect same "Unknown error occured!" from .net asp web services in iframe.

Comments

0

I had the same problem.

This one solved for me:

$result = $soapClient->somefunction(array( "param1" => "value1", "param2" => "value2" ));

Parameter types (and order) must be the same as what the current wsdl defines. (string, object, etc)

Comments

-4

try this,

$client->__soapCall('methodName',array('requestObj'=>$requestObj));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.