在PHP中使用SoapClient从WSDL获取元素
发布时间:2020-12-13 13:57:47 所属栏目:PHP教程 来源:网络整理
导读:我想从 Version中获取文字.嵌套在 service内的元素块的WSDL.有问题的WSDL是Ebay的Trading api.有关的片段看起来像这样: wsdl:service name="eBayAPIInterfaceService" wsdl:documentation Version941/Version /wsdl:documentation wsdl:port binding="ns:eB
我想从< Version>中获取文字.嵌套在< service>内的元素块的WSDL.有问题的WSDL是Ebay的Trading api.有关的片段看起来像这样:
<wsdl:service name="eBayAPIInterfaceService"> <wsdl:documentation> <Version>941</Version> </wsdl:documentation> <wsdl:port binding="ns:eBayAPISoapBinding" name="eBayAPI"> <wsdlsoap:address location="https://api.ebay.com/wsapi"/> </wsdl:port> </wsdl:service> 我正在这样做: $xml = new DOMDocument(); $xml->load($this->wsdl); $version = $xml->getElementsByTagName('Version')->item(0)->nodeValue; 这是有用的,但我想知道是否有一个方法来获得这个本机使用PHP的SOAP扩展? 我正在想像下面的工作,但它没有: $client = new SoapClient($this->wsdl); $version = $client->eBayAPIInterfaceService->Version;
用常规的SoapClient不可能做你想要的.你最好的办法是扩展SoapClient类并抽出这个要求来获取版本.
请注意,file_get_contents没有被缓存,所以它将始终加载WSDL文件.另一方面,SoapClient缓存WSDL,因此您将不得不自己处理它. 也许看看NuSOAP.您将能够修改代码以适合您的目的,而无需加载WSDL两次(当然您也可以修改SoapClient,但这是另一个冠军)) namespace Application; use DOMDocument; class SoapClient extends SoapClient { private $version = null; function __construct($wsdl,$options = array()) { $data = file_get_contents($wsdl); $xml = new DOMDocument(); $xml->loadXML($data); $this->version = $xml->getElementsByTagName('Version')->item(0)->nodeValue; // or just use $wsdl :P // this is just to reuse the already loaded WSDL $data = "data://text/plain;base64,".base64_encode($data); parent::__construct($data,$options); } public function getVersion() { return is_null($this->version) ? "Uknown" : $this->version; } } $client = new SoapClient("http://developer.ebay.com/webservices/latest/ebaysvc.wsdl"); var_dump($client->getVersion()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读