Dave
Dave

Reputation: 253

Creating a SOAP request with different kinds of parameters in PHP

I'm trying to make a SOAP request using PHP and I don't seem to be able to seperate my parameters I need to send with the call. I can use the service through out a SOAP testing tool, and the snippet I'm using there is (with ccn3 and ccn2 removed):

<?xml version="1.0" encoding="utf-8"?>
<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>
    <tns:GetUser>
      <tns:auth>
        <ccn3:Username>testuser</ccn3:Username>
        <ccn3:Password>testpass</ccn3:Password>
        <ccn3:AuthID>55125621</ccn3:AuthID>
      </tns:auth>
      <tns:user>
        <ccn2:Address>Testvägen 1</ccn2:Address>
        <ccn2:CustNo/>
        <ccn2:FirstName/>
        <ccn2:LastName/>
        <ccn2:SSN>1234567890</ccn2:SSN>
      </tns:user>
    </tns:GetUser>
  </soap:Body>
</soap:Envelope>

This do work and gives the desired answer from the service. But when connecting to it through php it doesn't. The php code I'm currently using looks like this:

<?php
    $username = "testuser";
    $password = "testpass";
    $authID = 55125621;


    $client = new SoapClient("https://url/service.svc?wsdl");
    $param = array(
        'Username'=>$username,
        'Password'=>$password,
        'AuthID'=>$AuthID,
        'Address'=>'Testvägen 1',
        'SSN'=>'1234567890',
        'FistName'=>'',
        'LastName'=>''
        );
    $res = $client->GetUser($param);

    echo "<pre>";
    print_r($res);
    echo "</pre>";
?>

In my XML query I'm using two "groups" of parameters. I send auth data towards my ccn3 (tns:auth) and my data to ccn2 (tns:user). I'm guessing that's my problem, but how do I do this seperation in php?

Upvotes: 0

Views: 68

Answers (1)

galkindev
galkindev

Reputation: 156

Try this:

$params = array(
        'auth' => array(
                    'Username' => $username,
                    'Password' => $password,
                    'AuthID' => $AuthID,
        ),
        'user' => array(
                    'Address' => 'Testvägen 1',
                    'SSN' => '1234567890',
                    'FistName' => '',
                    'LastName' => ''
        ));

        $res = $client->GetUser($params);

Upvotes: 1

Related Questions