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



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

// Consume web service
webserviceObj = createObject("webservice", webserviceURL);
responses = webserviceObj.incomingRequest(username, password, incomingrequest);
</cfscript>

and here is my php replica


$webserviceURL = "wisdl url";
$username = "username";
$password = "passward";

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

   echo("\
Dumping client object functions:\
");
   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 "\
\
\
";
        echo "Response:$Response\
";
        echo "\
\
\
";

        //debug
        echo "REQUEST:\
" . $client->__getLastRequest() . "\
"; //Shows query just sent
        echo "RESPONSE:\
" . $client->__getLastResponse() . "\
"; //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

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.


echo $client->incomingRequest($username, $password, 'request');

here is the wisdl url:

http://services.vtrenz.net/receiver.cfc?wsdl

bump… :frowning:

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

is the result of


var_dump($client->__getFunctions()); 
var_dump($client->__getTypes()); 
var_dump($client->__getLastResponse());

if you run just


<?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?

I used your wsdl file as r.wsdl, so the code was
ReceiverService.php

<?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 :slight_smile:

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?

If you have wsdl, then here is the easy way to go: wsdl2php