Magento – Correct way of creating custom SOAP API magento2

magento2

Please correct the below for creating custom SOAP API.

\Vendor\Module\etc\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
   <preference for="Vendor\Module\Api\Data\QueueInterface" type="Vendor\Module\Model\Queue" />
</config>

Vendor\Module\etc\webapi.xml

<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/sync/getProduct/:limit" method="GET">                                     
    <service class="Vendor\Module\Api\QueueRepositoryInterface" method="getProductUpdate"/>   
    <resources>
        <resource ref="anonymous" />
    </resources>
</route>

Vendor\Module\Api\QueueRepositoryInterface.php

namespace Vendor\Module\Api;

/**
 * Vendor\Module CRUD interface.
 * @api
*/
interface QueueRepositoryInterface
{
   public function getProductUpdate($limit); 
}

Here is my doubt

Is my Data file correcT?

Vendor\Module\Api\Data\QueueInterface.php

<?php

namespace Magento\Sales\Api;


interface OrderRepositoryInterface
{
   public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria);

   public function get($id);

   public function delete(\Magento\Sales\Api\Data\OrderInterface $entity);

   public function save(\Magento\Sales\Api\Data\OrderInterface $entity);
}

Vendor\Module\Model\Queue.php

namespace Vendor\Module\Model;

use Magento\Framework\Model\AbstractModel;
use Magento\Framework\DataObject\IdentityInterface;
use Vendor\Module\Api\Data\QueueInterface;

 class Queue extends AbstractModel implements QueueInterface,IdentityInterface
 {
    public function getProductUpdate($limit)
    {
    //echo 'getproductudate';die;
    if(!isset($limit)) 
    {
        return json_encode(array("result"=>false,"message" => 'Argument is missing'));
    }

    if(!$this->_status)
    {
        return json_encode(array("result"=>false,"message" => 'Vendor\Module Plugin is disabled'));;
    }

    if($this->_bulkImport == "enable")
    {
        return json_encode(array("result"=>false,"message" => 'Bulk Product Import in progress, Please try again later'));;  
    } 

    $data = $this->_helper->getProductUpdate($limit);
    if(isset($data))
    {   
        return json_encode(array("result" => true,"data" => $data));
    }

    return json_encode(array("result" => false,"message" => "Record not found"));
}
}

In my URL i tried:

http://localhost:1338/magento2x_3/soap/default?wsdl&services=moduleQueueRepositoryV1

I get

exception 'Exception' with message 'Report ID: webapi-57a85520a7648; Message: Requested service is not available: "syncQueueRepositoryV1"'

Best Answer

First you must find your API from list APIs:

http://magento_host/soap/default?wsdl_list=1 

See all Soap APIs in doc:

http://devdocs.magento.com/guides/v2.1/soap/bk-soap.html.

After use program for creating SOAP requests like SoapUI OpenSource

https://www.soapui.org/downloads/soapui.html