Jump to content

Php + Web Services Help


Marina111

Recommended Posts

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 "<P><P>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

Link to comment
Share on other sites

I have a software tool called SoapUI with which I can call the web service and get it to work, but I'm obviously missing something in the PHP and having never done web services before I'm struggling. The code from SOAPUI which does work and return a value is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:civ="http://schemas.datacontract.org/2004/07/Civica.Housing.Cx.WebServices.Contracts.DataContracts.Modules.Security">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetUserWSToken>
         <!--Optional:-->
         <tem:request>
            <civ:Password>xxx</civ:Password>
            <civ:UserName>yy</civ:UserName>
         </tem:request>
      </tem:GetUserWSToken>
   </soapenv:Body>
</soapenv:Envelope>

Link to comment
Share on other sites

And how about what PHP is sending? Can you see that?

class DebugSoapClient extends SoapClient {

	public function __doRequest($request, $location, $action, $version, $one_way = 0) {
		/* log $request somewhere */

		return parent::__doRequest($request, $location, $action, $version, $one_way);
	}

}
$client = new DebugSoapClient('https://xxx/cx/WebService/WSTokenService?singleWsdl');

 

Link to comment
Share on other sites

Seems like the "log $request somewhere" I put in there somehow turned into "dump $this". That is not what it needs to do. $request is the request. You need to see its value.

Or maybe you're dumping $request after all? It's XML so it could very well be invisible. Do a View Source of the page.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.