SoapClient does not send parameters
php, soap, wsdl
Solution
Try this:
class LogInInfo{
public $UserName = '1';
public $Password = '2';
public $CompanyDatabase = '3';
}
ini_set('display_error', 1);
error_reporting(E_ALL);
$client = new SoapClient('http://testi.lemonsoft.eu:22000/CTP/LemonWeb/UserServices.svc?singleWsdl', array(
'classmap'=>array('LogInInfo'=>'LogInInfo'),
'debug'=>true,
'trace'=>true
));
try {
$info = new LogInInfo();
$resp = $client->LogIn($info);
} catch(Exception $e) {
var_dump($e);
}
print_r($client->__getLastRequest());
Result:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.datacontract.org/2004/07/Lemonsoft.LemonsoftServiceLibrary.User" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
<ns2:LogIn xsi:type="ns1:LogInInfo">
<ns1:CompanyDatabase>3</ns1:CompanyDatabase>
<ns1:Password>2</ns1:Password>
<ns1:UserName>1</ns1:UserName>
</ns2:LogIn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Problem
I am pulling my hair out. I have tried many different ways, but nothing works: ``` <?php // Proxy is for Fiddler $soap = new soapClient( 'http://testi.lemonsoft.eu:22000/CTP/lemonweb/userservices.svc?wsdl', array( 'proxy_host' => 'localhost', 'proxy_port' => '8888' )); try { $test = new stdClass(); $test->UserName = "foo"; $test->Password = "bar"; $test->CompanyDatabase = "baz"; // This should work: print_r($soap->LogIn($test)); /** The rest are alternative experiments, no avail: **/ print_r($soap->LogIn(array($test))); print_r($soap->LogIn(array('parameters' => $test))); print_r($soap->login(array( 'UserName' => 'foo', 'Password' =>'bar', 'CompanyDatabase' => 'baz' ))); print_r($soap->__soapCall('LogIn', array('parameters' => $test))); print_r($soap->__soapCall('LogIn', array('parameters' => array( 'UserName' => 'foo', 'Password' =>'bar', 'CompanyDatabase' => 'baz' )))); print_r($soap->LogIn(new SoapParam($test, "LogIn"))); print_r($soap->LogIn(new SoapParam(array( 'UserName' => 'foo', 'Password' =>'bar', 'CompanyDatabase' => 'baz' ), "LogIn"))); print_r($soap->__soapCall('LogIn', array('parameters' => array( new SoapParam(array( 'UserName' => 'foo', 'Password' =>'bar', 'CompanyDatabase' => 'baz' ), "LogIn") )))); } catch (SoapFault $fault) { print_r($fault); } ?> ``` I captured the requests with fiddler and the response always looks like this: ``` <?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:LogIn/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ``` as if the LogIn parameters are never sent. Does the empty ns1:LogIn tag really mean that? Can there be some instance inbetween, which I can not control, for some reason stripping the parameters? According to my understanding the method LogIn takes one parameter, which, according to the documentation, should be a PHP stdClass.