0

Magento 1.9 I used the WSDL

https://github.com/marouanbmm/magento-Apis/blob/master/code/local/Tecnifibre/SerienFlow/etc/wsdl.xml

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 ?

0

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.

<?php
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);

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

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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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