Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuSoap - How to use local, existing WSDL file in nusoap_client PHP

I am new to nusoap, and web services in general.

The wsdl file comes from the client. I have a basic web service working with the default URL which supplies the wsdl via the web address: http://hiddenurl.com/ws/schema/Terminal.wsdl

But the client's documentation says: "Please download the WSDL and XML schema files locally for your code to use. Do not get those files every time from our server."

So I have been trying to host the wsdl file locally, or via my own web server, but neither have worked.

I have tried:

$wsdlUrl = 'http://supplied-url.com/schema/Terminal.wsdl'    // working but discouraged

$wsdlUrl = 'http://my-own-IIS-based-url/schema/Terminal.wsdl'    // url loads and I can
  // view wsdl file, but when I load run webservice is returns blank / nothing 

$wsdlUrl = 'path/to/local/Terminal.wsdl'    // returns blank or 'boolean'false'

$tempUrl = realpath('path/to/local/Terminal.wsdl')    // get absolute url
wsdlUrl = tempUrl;    // returns blank screen or 'boolean'false'

Is there any way I can have the web service use the wsdl file from a location other than the one originally supplied by the client? I've seen some references to web servers returning wsdl with a sort of http://getfile.php?file.wsdl but I don't understand what would be in the 'getfile.php' in order to deliver the wsdl via the query string.

Here is my PHP code to call the web service. Again, it works with the client supplied URL for the wsdl file, but not when I try to access the wsdl file any other way.

<?php
require_once('nusoap.php');

$URI = 'http://api.hiddenurl.com/ws/schema';

$env = 'api'; 
$wsdlUrl = 'http://'.$env.'.hiddenurl.com/schema/Terminal.wsdl';
$licenseKey = 'xxxx-xxxx-xxxx-xxxx-xxxx';
$userName = 'user';
$password = 'password';

$service = new nusoap_client($wsdlUrl, true);

// login credentials
$service->setHeaders(
'<wsse:Security xmlns:wsse="http://hiddenurl.xsd">'.
'<wsse:UsernameToken>'.
'<wsse:Username>'.$userName.'</wsse:Username>'.
'<wsse:Password Type="http://hiddenurl#PasswordText">'.$password.'</wsse:Password>'.
'</wsse:UsernameToken>'.
'</wsse:Security>'
);

$msg =
'<GetDetailsRequest xmlns="'.$URI .'">'.
'<messageId></messageId>'.
'<version></version>'.
'<licenseKey>'.$licenseKey.'</licenseKey>'.
'<iccids>'.
'<iccid>'.'xxxxxxxxxxxxxxx'.'</iccid>'.
'</iccids>'.
'</GetDetailsRequest>';

$result = $service->call('GetlDetails', $msg);

if ($service->fault) {
  echo 'faultcode: ' . $service->faultcode . "\n";
  echo 'faultstring: ' . $service->faultstring . "\n";
  echo 'faultDetail: ' . $service->faultdetail . "\n";
  echo 'response: ' . $service->response;
  exit(0);
}

echo "<pre>";
var_dump($result);
echo "</pre>";

?>

Many thanks.

like image 971
100pic Avatar asked Apr 29 '16 04:04

100pic


1 Answers

Try this

$wsdl_location= realpath('path/to/local/Terminal.wsdl');
$wsdl_cache = new nusoap_wsdlcache("/tmp"); // for caching purposes
$wsdl_obj = $wsdl_cache->get($wsdl_location);
if (empty($wsdl_obj)) {
  $wsdl_obj=new wsdl($wsdl_location);
  $wsdl_cache->put($wsdl_obj);
}
$service = new nusoap_client($wsdl_obj,true);
like image 72
Ihab Avatar answered Oct 19 '22 09:10

Ihab