Search code examples
phpxmlweb-servicessoapwsdl

SOAP working with xml via soapui but not with PHP


I am creating an SOAP client using PHP and having issues with consuming. When I test the request direct XML using soapui it responds fine and works but with PHP using SoapClient class it tells me the same credentials which I use in soapui are incorrect.

Not sure what I am missing here. My code below Below is my XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pric="http://upshot.co.uk/pricing_request_ws">
<soapenv:Header/>
<soapenv:Body>
<pric:retrieveProductsPricing>
<username>apiuser</username>
<password>pword</password>
<postcode>EC2R 7HP</postcode>
</pric:retrieveProductsPricing>
</soapenv:Body>
</soapenv:Envelope>

Below is my PHP

$wsdl   = "http://URL?wsdl";
$client = new SoapClient($wsdl, array('trace'=>1));

try
{
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$params = array(
    'User name' => 'apiuser',
    'Password' => 'pword',
    'Postcode' => 'EC2R 7HP'

);
$response = $client->retrieveProductsPricing($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);

This is my first time configuring a soap client so I'm sure I have potentially made a mistake in this.


Solution

  • Have a look at the first code:

    <username>apiuser</username>
    <password>pword</password>
    <postcode>EC2R 7HP</postcode>
    

    You should use the same keys for the array

    $params = array(
        'username' => 'apiuser',
        'password' => 'pword',
        'postcode' => 'EC2R 7HP'
    );
    

    Useful examples