Magento 1.9 I used the WSDL


file as part of my development Delphi win 32 to have access to the functions, arrays, objects etc... This was very helpful.

Actually I need to customize this module to use into Magento 2, so I must use wsdl file in Magento 2.

Can anyone enlighten me ?

1 Answer 1


I give you an exemple to how to use your custom SOAP wsdl.

You create a function in your block module, then you call this function where you want.

namespace Vendor\Module\Block;

class wsdl extends \Magento\Framework\View\Element\Template
    const USER = "User here";
    const PASSWORD = "pass here";

    protected $_customerSession;
    protected $_soapClientFactory;
    protected $_storeManager;
    protected $_logger;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Customer\Model\Session $customerSession,
        \Magento\Framework\Webapi\Soap\ClientFactory $soapClientFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Psr\Log\LoggerInterface $logger,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->_customerSession = $customerSession;
        $this->_soapClientFactory = $soapClientFactory;
        $this->_storeManager = $storeManager;
        $this->_logger = $logger;

     * @object call custom wsdl
    public function somefunctionName($param1)
        ini_set("soap.wsdl_cache_enabled", "0");

        $credentials = array('login' => self::USER, 'password' => self::PASSWORD);
        $options = array("trace" => 1, "exception" => 0, 'encoding' => 'UTF-8');
        $ServiceWeb_path = "ws/wsdl_path.xml";
        $url = $this->_storeManager->getStore()->getBaseUrl().$ServiceWeb_path;
        $soap = $this->_soapClientFactory->create($url, $credentials);

        try {
            $result = $soap->__soapCall("wsdl_method", array("parameters" => array("args0" => array("wsdl_param1" => $param1))));
            return $result;
            //\Zend_Debug::dump( "Request :\n".htmlspecialchars($soap->__getLastRequest()));

        } catch (\Exception $e) {
            $this->_logger->critical("SOAP ERROR : ".$e->getMessage());

Info : Your file.wsdl you put It in root project magentoProject/ws/file.wsdl, It is not a good idea to put here but, you can moove it in your module to do thigs better.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.