0

I need to send a SOAP request to a .NET Web Services (*.asmx). I am creating a WSDL SoapClient object and I need to make a __soapCall sending 2 parameters: LoginName and Password. The XML should be something like the exemple to work, but the XML created has the parameters all confused.

This is the code:

$client = new SoapClient("https://server/service.asmx?WSDL",array("trace"=>1,'soap_version' => SOAP_1_2)); 
$client->__setCookie('ticket',$ticket);
$param= array('LoginName'=>'name','Password'=>  base64_encode('123456'));
$client->__soapCall('AddPlayer', $param);
echo "REQUEST:\n" . htmlentities($sweepStakesClient->__getLastRequest()) . "\n";

Also tried:

$param = array(new SoapParam('name','LoginName'),new SoapParam(base64_encode('123456'),'Password'));

Echo returns:

REQUEST: <?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://server.com/Service">
<env:Body>
 <ns1:AddPlayer/>
  <Password>MTIyMzQ1NTY=</Password>
</env:Body>
</env:Envelope>

I need it to be something like:

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
    <AddPlayer xmlns="http://server.com/Service">
      <request>
        <LoginName>name</LoginName>
        <Password>MTIyMzQ1NTY=</Password>
      </request>
    </AddPlayer>
  </soap12:Body>
</soap12:Envelope>
  • What are you trying to accomplish here? A little more clarification would be useful :) – Shrout1 Jul 02 '15 at 18:43
  • Does the second answer here help? http://stackoverflow.com/questions/953639/connecting-to-ws-security-protected-web-service-with-php Not sure if you are trying to do Wsse auth. Think the StdClass approach over an array rings some bells though. – ficuscr Jul 02 '15 at 18:47
  • I need to send a SOAP request to a .NET Web Services (*.asmx). I am creating a WSDL SoapClient object and I need to make a __soapCall sending 2 parameters: LoginName and Password. The XML should be something like the exemple to work, but the XML created is all confused. – Fabio Rizzo Sciubba Jul 02 '15 at 18:50
  • Gotta love a good REST interface... You might like NuSOAP as a friendlier PHP soap client / wrapper. – ficuscr Jul 02 '15 at 18:57

1 Answers1

1

Please pay attention to the documentation provided on php.net regarding the method you use here, SoapClient::__soapCall():

This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.

You're in WSDL mode, so you don't need to use it at all. Instead call the method directly:

$client->AddPlayer('name', 'MTIyMzQ1NTY');

When you debug you should see that it matches up with the method name and the two parameters. In case not, fall-back to SoapClient::__call() and use the array with the named parameters again as second parameter. But it's much more comfortable to do it the WSDL style with named methods.

hakre
  • 193,403
  • 52
  • 435
  • 836