0

I need to integrate a web service, and its being like to days, and the closest I get is the following, maybe some of you have more experience than me in this kind of web service.

The XML request I need to generate is the following

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"         xmlns:v2="http://v2.services.cangooroo.net/" xmlns:can="Cangooroo.Webservice.V2">
<soapenv:Header/>
<soapenv:Body>
<v2:getCityData>
<v2:credentialClient>
<can:UserName>?</can:UserName>
<can:Password>?</can:Password>
</v2:credentialClient>
<v2:countryId>US</v2:countryId>
</v2:getCities>
</soapenv:Body>
</soapenv:Envelope>

My PHP code

 $client = new SoapClient("http://v2.cangooroo.net/ws/2013/common_a.asmx?WSDL", array(
       "trace" => 1,
       "compression" => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
   ));
    $login = array();
    $login[] = new SoapVar('*', XSD_STRING, null, null, 'UserName', 'Cangooroo.Webservice.V2' );
    $login[] = new SoapVar('*', XSD_STRING, null, null, 'Password', 'Cangooroo.Webservice.V2' );
    $rest = array();
    $rest[] = new SoapVar($login, SOAP_ENC_OBJECT, null, null, 'credentialClient' );
    $rest[] = new SoapVar('US', XSD_STRING, null, null, 'countryId');

    $options = array('location' => 'http://v2.cangooroo.net/ws/2013/common_a.asmx');

    try {
        $resp = $client->__soapCall('getCityData', $rest, $options);

        print_r($resp);
        echo "Request:<pre>" . htmlentities($client->__getLastRequest()) . "</pre>";
    }catch (SoapFault $e){
        echo "REQUEST:<pre>" . htmlentities($client->__getLastRequest()) . "</pre>";
        /*print_r($e);*/

The actual xml the PHP code above generates

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="Cangooroo.Webservice.V2" xmlns:ns2="http://ws_2013.services.cangooroo.net/">
<SOAP-ENV:Body>
<ns2:getCityData>
<ns1:UserName>*</ns1:UserName>
<ns1:Password>*</ns1:Password>
</ns2:getCityData><countryId>US</countryId></SOAP-ENV:Body></SOAP-ENV:Envelope>

Iam not really sure if this is the best way to do it, but I tryed others, with __soapCall, __doRequest, this last one I got the soapClient php core class extended (as a try) to connect, and nothing seems to work. Pls, I could use a little help here. Tks guys.

1 Answer 1

2

If you check the wsdl file in http://v2.cangooroo.net/ws/2013/common_a.asmx?WSDL you can see the definition of the getCityData

<s:element name="getCityData">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="credential" type="s1:ClientCredential"/>
            <s:element minOccurs="0" maxOccurs="1" name="countryId" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>

the operation getCityData has a credential parameter, not a credentialClient that is what you have in the code that you posted. I've tried with this code:

$wsdlAddress = "http://v2.cangooroo.net/ws/2013/common_a.asmx?WSDL";

$options = array(
    "soap_version" => SOAP_1_2,
    "cache_wsdl" => WSDL_CACHE_NONE,
    "exceptions" => false
);

$webServiceClient = new SoapClient($wsdlAddress, $options);

$requestData = array(
    "countryId" => "US",
    "credential" => array(
        "UserName" => "username",
        "Password" => "Password",
    ),
);

$response = $webServiceClient->__soapCall("getCityData", array("getCityData" => $requestData));

echo "<h2>getCityData Operation Test:</h2>";
echo "<pre>";
print_r($response);
echo "</pre>";

in the response i can see Err: Login_Fail - Invalid user or password., i think i'm getting a valid response. Try with my code and adapt it to your needs.

Happy coding

Sign up to request clarification or add additional context in comments.

1 Comment

Yes! It Works that way, and its a lot better! Thank you very much! I cant vote up, but I would. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.