2

I am using below code in M1 to establish the connection using SOAP:-

<?php

    class Company_Module_Helper_Webservice extends Company_Module_Helper_Basehelper
    {   
        private function Connect()
        {
            $WebserviceUrl = Mage::helper('module/systemvalues')->getSysValue('web_service_url');
            return new SoapClient($WebserviceUrl, array('cache_wsdl' => WSDL_CACHE_NONE));
        }
    } 

Now I want to establish SOAP connection in M2:-

<?php
namespace Company\Module\Helper;

class Webservice extends \Company\Module\Helper\Basehelper
{

    /**
     * @var \Company\Module\Helper\Systemvalues
     */
    protected $moduleSystemvaluesHelper;

    public function __construct(
        \Company\Module\Helper\Systemvalues $moduleSystemvaluesHelper
    ) {
        $this->moduleSystemvaluesHelper = $moduleSystemvaluesHelper;
    }
    public function Connect()
    {
        $WebserviceUrl = $this->moduleSystemvaluesHelper->getSysValue('web_service_url');
        $logger = \Magento\Framework\App\ObjectManager::getInstance()->get('\Psr\Log\LoggerInterface');
        $logger->debug($WebserviceUrl);
        /** below line work in M1, now I want write code for M2 to estibalsed the soap connection for my module  */
        return new SoapClient($WebserviceUrl, array('cache_wsdl' => WSDL_CACHE_NONE));
    }
}

Any help would be much appreciated.

1 Answer 1

0

After spent lot of time on this issue we found below solution, my that help you:-

<?php
namespace Company\Module\Helper;

class Webservice extends \Company\Module\Helper\Basehelper
{

    /**
     * @var \Company\Module\Helper\Systemvalues
     */
    protected $moduleSystemvaluesHelper;

    public function __construct(
        \Company\Module\Helper\Systemvalues $moduleSystemvaluesHelper
    ) {
        $this->moduleSystemvaluesHelper = $moduleSystemvaluesHelper;
    }
    public function Connect()
    {
        $WebserviceUrl = $this->khaosconnectSystemvaluesHelper->getSysValue('web_service_url');

        $trace = true;
        $exceptions = false;

        $opts = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false,));

        $context = stream_context_create($opts);
        $soapClient = new \Zend\Soap\Client($WebserviceUrl);
        $soapClient->setSoapVersion(SOAP_1_2);
        $soapClient->setStreamContext($context);        
        return $soapClient;
    }
}

and use connect function to access the api function as below:-

public function getSites()
{
    $client = $this->Connect();
    return $client->APIFunction(array('' => ''));        
}

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.