NuSoap-如何在NuSoap_client PHP中使用本地现有的WSDL文件


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

我是nusoap和web服务的新手。

wsdl文件来自客户端。我有一个使用默认URL的基本web服务,该URL通过web地址提供wsdl:http://hiddenurl.com/ws/schema/Terminal.wsdl

但客户的文件显示:"请在本地下载WSDL和XML架构文件供您的代码使用。不要每次都从我们的服务器获取这些文件。"

因此,我一直试图在本地或通过自己的web服务器托管wsdl文件,但两者都不起作用。

我试过:

$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'

有没有任何方法可以让web服务从客户端最初提供的位置以外的位置使用wsdl文件?我看到一些web服务器返回wsdl的引用http://getfile.php?file.wsdl但我不明白"getfile.php"中会有什么内容,以便通过查询字符串传递wsdl。

这是我用来调用web服务的PHP代码。同样,它使用客户端提供的wsdl文件的URL,但当我尝试以任何其他方式访问wsdl文件时,它就不起作用了。

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

非常感谢。

试试这个

$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);

尝试使用localhost路径:

$wsdlUrl='http://localhost/schema/Terminal.wsdl';

p.s.这个url在浏览器中不起作用,但可以通过服务器上的php脚本执行。