SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: SOAP Call

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOAP Call

    Hello,

    I am trying to make a SOAP call to an API service (i.e. login), but not sure if iam invoking the method correct. can someone please help?

    this is an example the API service provider has given in cold fusion
    PHP Code:

    <!--- Consume webservice --->
    <
    cfscript>
    // DECLARE VARS
    webserviceURL "wisdl url";
    username "email@mycompany.com";
    password "mypassword123";

    // Consume web service
    webserviceObj createObject("webservice"webserviceURL);
    responses webserviceObj.incomingRequest(usernamepasswordincomingrequest);
    </
    cfscript
    and here is my php replica
    PHP Code:
    $webserviceURL "wisdl url";
    $username "username";
    $password "passward";

    $client = new SoapClient($webserviceURL);
    $client->incomingRequest($username$password'request');
    /*

       echo("\nDumping client object functions:\n");
       var_dump($client->__getFunctions());
       */

    //debug (and figuring out what to do!)
            //get functions and params
            
    var_dump($client->__getFunctions());
            
    var_dump($client->__getTypes());

            
    $Response $client->__getLastResponse();

            echo 
    "\n\n\n";
            echo 
    "Response:$Response\n";
            echo 
    "\n\n\n";

            
    //debug
            
    echo "REQUEST:\n" $client->__getLastRequest() . "\n"//Shows query just sent
            
    echo "RESPONSE:\n" $client->__getLastResponse() . "\n"//gets the data

            
    return $Response
    but i get this responce:

    array(1) { [0]=> string(75) "string incomingRequest(string $username, string $password, string $request)" } array(1) { [0]=> string(33) "struct CFCInvocationException { }" }

    thanks

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that the error is not obvious and regular as far as I know since it is echoing the PHP code itself. If the service provider provide some examples or help then you can ask them once. Since i don't know what incomingRequest() method returns because I havent seen your wsdl file yet, so try to echo the returned value by this method incomingRequest() once what it echos.
    PHP Code:
    echo $client->incomingRequest($username$password'request'); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump...

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array(1) { [0]=> string(75) "string incomingRequest(string $username, string $password, string $request)" } array(1) { [0]=> string(33) "struct CFCInvocationException { }" }
    is the result of
    Code:
    var_dump($client->__getFunctions()); 
    var_dump($client->__getTypes()); 
    var_dump($client->__getLastResponse());
    if you run just
    PHP Code:
    <?php
    $webserviceURL 
    "http://services.vtrenz.net/receiver.cfc?wsdl";
    $client = new SoapClient($webserviceURL);
    var_dump($client->__getFunctions()); 
    var_dump($client->__getTypes()); 
    var_dump($client->__getLastResponse());
    ?>
    Practically you have not yet sent any request, so you will not get any response.

  6. #6
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coolR View Post
    is the result of
    Code:
    var_dump($client->__getFunctions()); 
    var_dump($client->__getTypes()); 
    var_dump($client->__getLastResponse());
    if you run just
    PHP Code:
    <?php
    $webserviceURL 
    "http://services.vtrenz.net/receiver.cfc?wsdl";
    $client = new SoapClient($webserviceURL);
    var_dump($client->__getFunctions()); 
    var_dump($client->__getTypes()); 
    var_dump($client->__getLastResponse());
    ?>
    Practically you have not yet sent any request, so you will not get any response.
    coolR thanks for the reply. I actually thought there should still be some sort of response. I was actually going to give up and use curl to post the raw xml.

    so, then how do i submit a request? do need to look up the method on their wisdl or how do I do it?

  7. #7
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used your wsdl file as r.wsdl, so the code was
    ReceiverService.php
    PHP Code:
    <?php

    if (!class_exists("CFCInvocationException")) {
    class 
    CFCInvocationException {
    }}

    if (!
    class_exists("ReceiverService")) {
    class 
    ReceiverService extends SoapClient {
            private static 
    $classmap = array(
            
    "CFCInvocationException" => "CFCInvocationException",
        );

            public function 
    __construct($wsdl="r.wsdl"$options=array()) {
            foreach(
    self::$classmap as $wsdlClassName => $phpClassName) {
                if(!isset(
    $options['classmap'][$wsdlClassName])) {
                    
    $options['classmap'][$wsdlClassName] = $phpClassName;
                }
            }
            
    parent::__construct($wsdl$options);
        }

            public function 
    _checkArguments($arguments$validParameters) {
            
    $variables "";
            foreach (
    $arguments as $arg) {
                
    $type gettype($arg);
                if (
    $type == "object") {
                    
    $type get_class($arg);
                }
                
    $variables .= "(".$type.")";
            }
            if (!
    in_array($variables$validParameters)) {
                throw new 
    Exception("Invalid parameter types: ".str_replace(")("", "$variables));
            }
            return 
    true;
        }

            public function 
    incomingRequest($mixed null) {
            
    $validParameters = array(
                
    "(string)(string)(string)",
            );
            
    $args func_get_args();
            
    $this->_checkArguments($args$validParameters);
            return 
    $this->__soapCall("incomingRequest"$args);
        }


    }}

    ?>

  8. #8
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coolR View Post
    I used your wsdl file as r.wsdl, so the code was
    ReceiverService.php
    PHP Code:
    <?php

    if (!class_exists("CFCInvocationException")) {
    class 
    CFCInvocationException {
    }}

    if (!
    class_exists("ReceiverService")) {
    class 
    ReceiverService extends SoapClient {
            private static 
    $classmap = array(
            
    "CFCInvocationException" => "CFCInvocationException",
        );

            public function 
    __construct($wsdl="r.wsdl"$options=array()) {
            foreach(
    self::$classmap as $wsdlClassName => $phpClassName) {
                if(!isset(
    $options['classmap'][$wsdlClassName])) {
                    
    $options['classmap'][$wsdlClassName] = $phpClassName;
                }
            }
            
    parent::__construct($wsdl$options);
        }

            public function 
    _checkArguments($arguments$validParameters) {
            
    $variables "";
            foreach (
    $arguments as $arg) {
                
    $type gettype($arg);
                if (
    $type == "object") {
                    
    $type get_class($arg);
                }
                
    $variables .= "(".$type.")";
            }
            if (!
    in_array($variables$validParameters)) {
                throw new 
    Exception("Invalid parameter types: ".str_replace(")("", "$variables));
            }
            return 
    true;
        }

            public function 
    incomingRequest($mixed null) {
            
    $validParameters = array(
                
    "(string)(string)(string)",
            );
            
    $args func_get_args();
            
    $this->_checkArguments($args$validParameters);
            return 
    $this->__soapCall("incomingRequest"$args);
        }


    }}

    ?>
    needless to say, you are cool indeed

    so now I may sound stupid, but what is your code doing?

    can you tell me where i should place the username, password, and request in your code?

  9. #9
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have wsdl, then here is the easy way to go: wsdl2php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •