1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trying SOAP and PHP with no luck?

Discussion in 'PHP' started by 123GoToAndPlay, Feb 9, 2007.

  1. #1
    Hi all,

    I am trying to get a grisp on the soap/php subject. I have read some articles and now I have tried the following (php4 and nusoap.php)

    
    <?php include('nusoap.php');
       $client = new SoapClient("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl");
    
       echo("\nReturning value of getTemp() call: ".$client->getTemp("12345"));
    
    ?>
    
    Code (markup):
    But I get an error message:
    Fatal error: Call to undefined function: gettemp()

    But gettemp is a operation node???
    SEMrush
    Anyone knows how I can fix this or anyone knows another simple example??
     
    123GoToAndPlay, Feb 9, 2007 IP
    SEMrush
  2. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #2
    You are not calling service in a right way try following code

    
    <?php include('nusoap.php');
       $client = new SoapClient("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl");
    
       echo("\nReturning value of getTemp() call: ".$client->call("getTemp", "12345"));
    
    ?>
    
    PHP:
    I am assuming that function you want to call from wsdl is getTemp() Hope it helps.
     
    designcode, Feb 9, 2007 IP
  3. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #3
    Operations are not called in they way you are calling, i.e.
    $client->myMethod("parameters");

    Because myMethod is not a member function of object client so it will give error "Call to undefined function:"

    Instead you can call it as,

    $client->call("myMethod", "parameters");
     
    designcode, Feb 9, 2007 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @designcode,

    Tx for your answer and explanation. Unfortunatly it didn't fix my problem.

    Let me explain, I am trying to recreate the following http://www.herongyang.com/php/php_soap.html ->
    the "GetTemp.php - First Example with SOAP" part, but in my case with php4 and nusoap.php.

    code sofar
    
    include('nusoap.php');
       $client = new SoapClient("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl", 'wsdl');
    	echo "\nReturning value of getTemp() call: ".$client->call("getTemp", "12345");
    
    Code (markup):
    which gives me
    so I print_r
    and now I get
    So gettemp isn't found, but in http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl

    I can see
    Just started learning SOAP

    ( I am doing all of this to learn a bit more about webservices as I am about to make use of a service.asmx for a project).

    ps: do you have a simple working code example for me to look at and learn??
     
    123GoToAndPlay, Feb 9, 2007 IP
  5. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #5
    Did you try a valid location?
     
    noppid, Feb 9, 2007 IP
  6. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hmm, tx to another forum I do have the same output as the example url

    
    // include class
    include("nusoap.php");
    // create a instance of the SOAP client object
    $soapclient = new soapclient("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl",true);
    // set up an array containing input parameters to be
    // passed to the remote procedure
    $params = array('zipcode' => 12345);
    // invoke the method
    $result = $soapclient->call('getTemp',$params);
    // print the results of the search
    print_r($result);
    die();
    
    PHP:
    Only how do you know 12345 is a zipcode??? The $params part is a bit unclear to me.
    Ok I know getTemp is a function and $params are the params for this function. But how do I check which params can be used??
     
    123GoToAndPlay, Feb 9, 2007 IP
  7. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #7
    designcode, Feb 9, 2007 IP
  8. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #8
    Listen, see the following part of WSDL

    <operation name="getTemp">
    <input message="tns:getTempRequest"/>
    <output message="tns:getTempResponse"/>
    </operation>
    Code (markup):
    <input> is the basically the parameters of function and <output> is the value returned by service.

    No look at the message attribute of input, If its tns:something, then try to find "something" in the WSDL, and the parameters you will pass will be array, like

    $client->call("myFunc", array("param1"=>"abcd"));
    Code (markup):
    and message attribute is xsd:something, then you will have to send a single parameter, like

    $client->call("myFunc","abcd");
    Code (markup):
     
    designcode, Feb 9, 2007 IP
    123GoToAndPlay likes this.
  9. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hmm ok the zipcode part
     
    123GoToAndPlay, Feb 9, 2007 IP
  10. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #10
    Sorry i didn't catch what u r trying to say?
     
    designcode, Feb 9, 2007 IP
  11. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    @designcode, tx for your answers

    I see the zipcode part now and tns <-> xsd is array vs single parameter

    I am reading your tutorialsgarden.com/developers/docs/rateTutorial/ as the request and response looks like the webservice I need to use.

    Great site you have there!
     
    123GoToAndPlay, Feb 9, 2007 IP
  12. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #12
    Thanks mate for liking my website, if my post helped you please add it to my reputation :) and feel free to post your questions if you have problems/queries with webservices.

    Enjoy :)
     
    designcode, Feb 9, 2007 IP