SoapClient 的 WSDL 放在哪里以及如何引用
我确信这是一个愚蠢的新手问题,但这是我第一次使用 SOAP,所以我想我符合资格。我在尝试从 PHP 类中加载本地 WSDL 文件时遇到了很大的麻烦。我不明白它在哪里寻找该文件或如何在本地引用它。我可以使用完整的网站网址来放置绝对路径,但这似乎有点矫枉过正,而且它只适用于这个网站。我更喜欢使用相对路径引用该文件。
我正在使用 PHP 和 Magento 商店。处理与 SOAP 服务器的通信的类是 Namespace_Module_Model_Carrier_Fedex_Addressvalidation
,它位于 app/code/local/Namespace/Module/Model/Carrier/Fedex/Addressvalidation.php
。此类的实例是使用 Namespace_Module_Model_Carrier_Fedex
类中的 Mage::getModel('shippingrates/rier_fedex_addressvalidation')
实例化的。 WSDL 位置定义在地址验证类的顶部:
protected $_wsdl = 'AddressValidationService_v2.wsdl';
在模型的构造函数中,我初始化 SoapClient:
$this->_client = new SoapClient($this->_wsdl);
$this->_client->__setLocation($this->getServiceLocation());//returns a remote URL for their test server
该文件位于与 Addressvalidation.php 文件相同的目录中,但我有还尝试将其定位在与 Fedex.php 脚本相同的目录以及 app/code/local/ 中,但没有任何效果。我尝试将 WSDL 变量设置为 ./AddressValidationService_v2.wsdl 以及各种其他选项,但我总是遇到这样的异常:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from './AddressValidationService_v2.wsdl' : failed to load external entity
如果有人可以帮助我了解 SoapClient 的范围和位置我想我会更好地理解这些文件的放置位置以及如何引用它们。
I'm certain this is a dumb newbie question, but this is the first time I'm working with SOAP, so I guess I qualify. I'm having a heck of a time trying to load a local WSDL file from within my PHP class. I don't understand where it is looking for the file or how I can reference it locally. I could put the absolute path using the full website url, but that seems like overkill and it would ONLY work on this site. I'd prefer to reference the file using a relative path.
I'm using PHP with a Magento store. The class that handles communication with the SOAP server is Namespace_Module_Model_Carrier_Fedex_Addressvalidation
, which is located at app/code/local/Namespace/Module/Model/Carrier/Fedex/Addressvalidation.php
. An instance of this class is instantiated using Mage::getModel('shippingrates/carrier_fedex_addressvalidation')
from within the Namespace_Module_Model_Carrier_Fedex
class. The WSDL location is defined at the top of the address validation class:
protected $_wsdl = 'AddressValidationService_v2.wsdl';
Within the constructor of the model I initialize the SoapClient:
$this->_client = new SoapClient($this->_wsdl);
$this->_client->__setLocation($this->getServiceLocation());//returns a remote URL for their test server
The file is located in the same directory as the Addressvalidation.php file, but I have also tried locating it in the same directory as the Fedex.php script as well as at app/code/local/ but nothing works. I have tried setting the WSDL variable to ./AddressValidationService_v2.wsdl as well as various other options but I always get an exception like this:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from './AddressValidationService_v2.wsdl' : failed to load external entity
If someone can please help me understand the scope and where the SoapClient looks for the files I think I'll have a better understanding of where to put them and how to reference them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,WSDL 文件指向 URL,而不是本地文件。
因此,如果您在本地 PC 上设置并运行了 Web 服务,那么您可以通过以下方式设置客户端进行测试:
这实际上来自我的计算机上正在运行的 PHP 脚本。我用这种方式测试了我自己的 SoapServer 并且它有效。 “
getDetails
”是 WSDL 文件中定义的一种方法,它需要一个参数,我将其作为$id
传递。调用后输出调试行,这对我很有帮助。
Usually the WSDL file points to the URL not to a local file.
So if you have a web service set up and running on your local PC, this is how you could set up your client for testing:
This is actually from a working PHP script on my computer. I test my own SoapServer this way and it works. "
getDetails
" is a method defined in WSDL file and it expects one parameter, which I pass as$id
.The debugging lines are output after the call, which is very helpful to me.
结果我的 Apache 服务器配置错误。它将我的请求重定向到“localhost”到同一服务器上的另一个虚拟主机。当我尝试从浏览器加载 WSDL 文件时,它工作正常,但从服务器上的脚本加载却不行。它仍然不起作用,但至少我已经取得了进步。
Turns out I had a mis configuration in my Apache server. It was redirecting my request to "localhost" over to another virtual host on the same server. When I tried loading the WSDL file from my browser it worked fine but from the script on the server it did not. It's still not working, but I've made progress at least.