Help with PHP + Web Services

Hi,

I’m struggling to get a web service to work which we are using to integrate with a software package from Civica. Unfortunately they have sent us code in visual basic which we don’t use here and I’m struggling to “translate” the visual basic into PHP.

So here’s the code I have so far:

error_reporting(E_ALL);

$client = new SoapClient(‘https://xxx/cx/WebService/WSTokenService?singleWsdl’);
var_dump($client->__getFunctions());

The above works and I can see the functions. It’s the next bit I can’t get to work:

$request_param = array(‘Password’ => ‘xxx’, ‘UserName’ => ‘yyy’);

try
{
$request = $client ->GetUserWSToken($request_param);
$result = $request ->GetUserWSTokenResult;
//print_r($result);
}
catch (Exception $e)
{
echo “

Exception Error!”;
echo $e->getMessage();
}

When I run the above code I get an error message “Exception Error!GetUserWSToken has service faults”.

The visual basic code we’ve been sent by the package company to use is:

Dim tokenClient As New TokenService.WSTokenServiceClient
Dim tokenreq As New TokenService.SecurityTokenRequest
tokenreq.UserName = “usernamehere”
tokenreq.Password = “passwordhere”
Dim token = tokenClient.GetUserWSToken(tokenreq)

Does anyone know how to translate the visual basic above into what I need to do for PHP?

Thanks,

Marina

I think I’m a bit further forward - the parameter for GetUserWSToken needs to be a SecurityTokenRequest and the username and password are variables within SecurityTokenRequest, however I’m struggling with the syntax to get this right. Can anyone help?

I’m not experienced in Soap much. But, to add in usernames and passwords, normally you do it before you create the client. Loosely something like:
$options = array(
‘login’ => $username,
‘password’ => $password,
);
$client = new SoapClient($wsdl, $options);
Of course this depends on your soap set up on the other end. Sometimes it is not “login” but “username”, etc. So loosely, your version would be something like:

error_reporting(E_ALL);
$options = array(‘username’ => $username, ‘password’ => $password);
$client = new SoapClient(‘https://xxx/cx/WebService/WSTokenService?singleWsdl’, $options);

The TRY section would not be needed. You would then add your soap request to handle the data section. Not good at soap, but, think this will help.

Sponsor our Newsletter | Privacy Policy | Terms of Service