1

I am trying to consume a web service with no success. It looks like the xml is no properly set.

This is my PHP code:

<?php

$wsdlUrl = "http://api.clickatell.com/soap/webservice.php?WSDL";
$serviceUrl = "http://api.clickatell.com/soap/webservice.php";

    $request = array("user"=>"anyuser",
                "password"=>"asdsda",
                "api_id"=>"1234"
                );

var_dump($request);

try {
    $client = new SoapClient($wsdlUrl, array("trace" => 1, "location" => $serviceUrl));
    var_dump($client);
    echo "\n";
    $response = $client->auth($request);
    var_dump($response);
    var_dump($client->__getLastRequest());

    echo "\n";
}
catch(Exception $exp) {
    echo "EXCEPTION";
}

?>

And the SOAP packet is:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.clickatell.com/soap/webservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:auth>
            <api_id xsi:type="xsd:int">1</api_id>
            <user xsi:nil="true"/>
            <password xsi:nil="true"/>
        </ns1:auth>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What is wrong with the code that causes that api_id, user and password are not being sent?

4

1 回答 1

2

If you check out var_dump($client->__getFunctions()), you can see, that the parameters have to be passed like with a normal function call.

So you could do either the verbose thing with SoapParam:

$response = $client->auth(
    new SoapParam($request["api_id"], "api_id"),
    new SoapParam($request["user"], "user"),
    new SoapParam($request["password"], "password")
);

Or less verbose by just giving the parameters directly:

$response = $client->auth($request["api_id"],
    $request["user"], $request["password"]);
于 2012-10-14T16:03:45.393 回答