Mageician
Mageician

Reputation: 2927

Magento, SoapClient, and local WSDL

This is probably a newbie face-palm question, but I can't figure this out. I'm working with a web service from a Magento store (i.e. code in the Magento store is accessing a remote web service). It so happens in this case I have a local WSDL file that I need to reference. I've done this before using a remote URL to the WSDL file and that works fine. However, with a local file, I can't figure out how to reference it. I have it working by putting the file in a wsdl subdirectory of the root of the site and then I can reference it using http://mysite/wsdl/thefile.wsdl. However, I'd prefer to use a relative path to reference it (mainly due to the fact that I plan to deploy this same code to different sites and I'd like to use the same code for all).

I guess my question comes down to this: When you instantiate an instance of PHP's SoapClient like this $client = new SoapClient("thefile.wsdl"), where is it looking for thefile.wsdl? I thought it would be local to the PHP file that instantiates the SoapClient, but it didn't work when I put the file in the same folder. I tried the /includes directory as well as app/code/local.

I'm sure this is a no brainer for seasoned programmers, but sometimes the basics allude me...

Upvotes: 1

Views: 4892

Answers (4)

Jonathan Day
Jonathan Day

Reputation: 18692

You need to use Magento's in-built functions that generate a local file path. Storing the WSDL in the media directory may not be wise as this is publicly accessible (that may be the reason that the WSDL is not hosted remotely @AlanStorm).

I would recommend that you store the file in your custom module's etc directory. Example code:

$vWsdlPath = Mage::getModuleDir('etc', 'YourModule_NameHere').'/wsdl/SomeFile.wsdl';
$soap = new Zend_Soap_Client($vWsdlPath, $aOptions);

Upvotes: 0

Jevgeni Smirnov
Jevgeni Smirnov

Reputation: 3797

If your question is about magento, then you should create module. Create wsdl.xml(watch catalog's module wsdl.xml and api.xml files as an example).

More about magento soap api here

UPDATE 1

Well if the service is on another host, then you should be able to consume in the same manner as with magento service consumption.

Checkout this link about zend's fm

Upvotes: 0

Mageician
Mageician

Reputation: 2927

Mystery Solved! This is probably obvious to most, but I had to learn it, so perhaps someone else will benefit from it too.

I didn't realize that, due to Magento's design, the "root" of all pages is /index.php. EVERY page is loaded from that, so OF COURSE it's the root. When you try to instantiate a SoapClient, it looks in the directory of the main root script file, not the current module/class file. I could put the WSDL files in the root of the webserver and loaded them successfully (I guess I hadn't tried that before...).

What I've done now is to move them to the /media directory and I call them up by getting the media directory using getBaseDir('media'), tack on my sub-directory path, and VIOLA!

Upvotes: 3

Alana Storm
Alana Storm

Reputation: 166086

I'm not a SOAP guy, but your question doesn't make sense. Soap is a protocol for making remote method calls over HTTP. A WSDL file is the file the client requests from the remote server to ask what methods are available and how they can and should be called. A "local WSDL file" doesn't make sense.

Upvotes: 2

Related Questions