Quantcast
Channel: PHP Website Development » WSDL
Viewing all articles
Browse latest Browse all 11

PHP SoapServer always calls the same function despite callin

$
0
0

My SOAP server is (intended to be) setup with three operations: login, logout, and version.
The login function’s code is currently “faking” it at the moment, accepting two parameters, a username and password, automatically “authenticating” them by storing them in the function class’ private username and password variables. I have a session started at the entry point of the web service action, and when setting the function class in the SoapServer during initialization, I’m persisting connections as follows:
$this->setClass(‘WebSvcSoapFunctions’);
$this->setPersistence(SOAP_PERSISTENCE_SESSION); When I create a SOAP CLIENT and call my service, regardless of which function is called, it appears that the version() function is always executed rather than the one called. I imagine this is probably due to the way my WSDL is written, but I can’t see a problem (i’m new)….
I have the following WSDL listening via a PHP SoapServer:





































































My SOAP function class is as follows (included in my SOapServer via setClass()):
class WebSvcSoapFunctions
{
private $username = ”; // username provided by the client during login() request
private $password = ”; // password provided by the client during login() request

/**
* Handle a login request
*
* @param string $user – Client’s Username
* @param string $pass – Client’s Password
*/
public function login($user,$pass)
{
$this->username = $user;
$this->password = $pass;

// should check for validity here, but for testing, return true.
return ‘Successful Login. Welcome, ‘.$user;
}

/**
* Logs the client out.
*
*/
public function logout()
{
$this->username = ”;
$this->password = ”;
$_SESSION = array();
session_destroy();
return ‘Logged Out Successfully.’;
}
/**
* checks if the client has logged in successfully
*
* @return bool – true=logged in, false = unauthenticated
*/
private function isAuthenticated()
{
if (isset($this->username) && $this->username != ”)
{
return true;
}
else
{
return false;
}
}

/**
* Returns the version of the SOAP Server to the requesting client
*
*/
public function version()
{
if ($this->isAuthenticated())
{
return ‘Affinegy Service v1.0.0′;
}
else
{
return ‘NOT AUTHORIZED.’;
}
}
}
My SOAP CLIENT test class is as follows:
ini_set(“soap.wsdl_cache_enabled”, “0″);
define(‘WSDL_URL’,'http://soap.jrimer-amp64/?wsdl’);
try
{
$client = new SoapClient(WSDL_URL, array(‘trace’=>true));

$request = ‘version’;
$args = array();
$SOAPResult = $client->$request($args); // call the SOAP Server’s “version” function
OutputLastRequestResponse($client, $request, $args, $SOAPResult);

$request = ‘login’;
$args['username'] = ‘testuser’;
$args['password'] = ’1234′;
$SOAPResult = $client->$request($args); // call the SOAP Server’s “login” function
OutputLastRequestResponse($client, $request, $args, $SOAPResult);

$request = ‘version’;
$args = array();
$SOAPResult = $client->$request($args); // call the SOAP Server’s “version” function
OutputLastRequestResponse($client, $request, $args, $SOAPResult);

$request = ‘logout’;
$args = array();
$SOAPResult = $client->$request($args); // call the SOAP Server’s “logout” function
OutputLastRequestResponse($client, $request, $args, $SOAPResult);

$request = ‘version’;
$SOAPResult = $client->$request($args); // call the SOAP Server’s “version” function
OutputLastRequestResponse($client, $request, $args, $SOAPResult);

}
catch (Exception $e)
{
echo ‘

FAILED: '.print_r($e,1).'

‘; // dump the client exception to screen

OutputLastRequestResponse($client);
}

/**
* Displays the request and response of the test service call
*
* @param SoapServer $client – Object of type SoapClient that does the request
* @param string $requested – name of the SOAP function called
* @param array $args – Arguments sent to the SOAP function
* @param string $returned – PHP readable value returned by the client calling the provided SOAP function
*/
function OutputLastRequestResponse($client, $requested = ”, $args=array(), $returned=”)
{
echo ‘

XXXXXXXX SERVICE SOAP SERVER TEST

‘;
echo ‘Request:

'.$requested.'

‘;
echo ‘Request Arguments:

'.print_r($args,1).'

‘;
echo ‘Returned:

'.$returned.'

‘;
echo ‘Raw Request:

'.htmlspecialchars($client->__getLastRequestHeaders());
echo htmlspecialchars($client->__getLastRequest()).'

‘;
echo ‘Raw Response:

'.htmlspecialchars($client->__getLastResponseHeaders())."\n";
echo htmlspecialchars($client->__getLastResponse()).'

‘;
}
The results from the test class runs are as follows… Notice “NOT AUTHORIZED.” is the response to everything, indicating that ONLY the WebSvcSoapFunctions::version() function is running
Xxxxxx SERVICE SOAP SERVER TEST Request:
version
Request Arguments:
Array ( )
Returned:
NOT AUTHORIZED.
Raw Request:
POST / HTTP/1.1 Host: soap.jrimer-amp64 Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.10 Content-Type: text/xml; charset=utf-8 SOAPAction: “http://soap.jrimer-amp64/” Content-Length: 227
Raw Response:
HTTP/1.1 200 OK Date: Thu, 16 Jun 2011 19:43:32 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.10 Set-Cookie: PHPSESSID=scbuin269990ahfargfq7k0972; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 209 Connection: close Content-Type: text/xml; charset=utf-8
NOT AUTHORIZED.
Xxxxxx SERVICE SOAP SERVER TEST Request:
login
Request Arguments:
Array ( [username] => jrimer [password] => 1234 )
Returned:
NOT AUTHORIZED.
Raw Request:
POST / HTTP/1.1 Host: soap.jrimer-amp64 Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.10 Content-Type: text/xml; charset=utf-8 SOAPAction: “http://soap.jrimer-amp64/” Content-Length: 298 Cookie: PHPSESSID=scbuin269990ahfargfq7k0972;
usernamejrimerpassword1234
Raw Response:
HTTP/1.1 200 OK Date: Thu, 16 Jun 2011 19:43:32 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.10 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 209 Connection: close Content-Type: text/xml; charset=utf-8
NOT AUTHORIZED.
Xxxxxx SERVICE SOAP SERVER TEST Request:
version
Request Arguments:
Array ( )
Returned:
NOT AUTHORIZED.
Raw Request:
POST / HTTP/1.1 Host: soap.jrimer-amp64 Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.10 Content-Type: text/xml; charset=utf-8 SOAPAction: “http://soap.jrimer-amp64/” Content-Length: 227 Cookie: PHPSESSID=scbuin269990ahfargfq7k0972;
Raw Response:
HTTP/1.1 200 OK Date: Thu, 16 Jun 2011 19:43:32 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.10 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 209 Connection: close Content-Type: text/xml; charset=utf-8
NOT AUTHORIZED.
Xxxxxx SERVICE SOAP SERVER TEST Request:
logout
Request Arguments:
Array ( )
Returned:
NOT AUTHORIZED.
Raw Request:
POST / HTTP/1.1 Host: soap.jrimer-amp64 Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.10 Content-Type: text/xml; charset=utf-8 SOAPAction: “http://soap.jrimer-amp64/” Content-Length: 227 Cookie: PHPSESSID=scbuin269990ahfargfq7k0972;
Raw Response:
HTTP/1.1 200 OK Date: Thu, 16 Jun 2011 19:43:32 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.10 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 209 Connection: close Content-Type: text/xml; charset=utf-8
NOT AUTHORIZED.
Xxxxxx SERVICE SOAP SERVER TEST Request:
version
Request Arguments:
Array ( )
Returned:
NOT AUTHORIZED.
Raw Request:
POST / HTTP/1.1 Host: soap.jrimer-amp64 Connection: Keep-Alive User-Agent: PHP-SOAP/5.2.10 Content-Type: text/xml; charset=utf-8 SOAPAction: “http://soap.jrimer-amp64/” Content-Length: 227 Cookie: PHPSESSID=scbuin269990ahfargfq7k0972;
Raw Response:
HTTP/1.1 200 OK Date: Thu, 16 Jun 2011 19:43:32 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.2.10 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 209 Connection: close Content-Type: text/xml; charset=utf-8
NOT AUTHORIZED.
Any ideas what’s going on?
NOTE: I notice that if I simply comment out the definition in the WSDL for the VERSION function that the next defined function becomes the “always called” function (login)… What do I have configured wrong in that WSDL?
…………………………………..

Yeah, it was the WSDL, I completely have it misdefined… Restructured the WSDL and it fields requests correctly now…


Viewing all articles
Browse latest Browse all 11

Trending Articles