Пользовательский метод API V2 не является допустимым методом для этой службы


Я создал пользовательский метод для API SOAP Magento, и до сих пор он работал хорошо. Теперь я хочу создать тот же метод для Magento SOAP API версии 2.

Я создал WSDL.xml и тот V2.php Файлы классов (ниже), и когда я пытаюсь вызвать свой метод в API версии 2, я получаю следующую ошибку:

Uncaught SoapFault exception: [Client] Function ("pacoteCreatelink") is not a valid method for this service in [...]

Хотя ошибка очевидна, мне кажется, что мой новый метод в soap v2 не распознается. Я должен кое-что передать. Какой-нибудь Идеи?

Файлы:

Company
    Bundleapi
        etc
            config.xml
            api.xml
            wsdl.xml
        Model
            Pacote
                Api
                    V2.php
                Api.php

V2.php:

<?php
class Company_Bundleapi_Model_Pacote_Api_V2 extends Company_Bundleapi_Model_Pacote_Api
{
    public function createlink($message)
    {
        return $message;
    }
}

Api.xml:

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <bundle_link translate="title" module="company_bundleapi">
                <title>Create Bundle link</title>
                <model>bundleapi/pacote_api</model>
                <methods>
                    <createlink translate="title" module="company_bundleapi">
                        <title>Create link Options Bundle</title>
                    </createlink>
                    <cleanlink translate="title" module="company_bundleapi">
                        <title>Clean link beetwen Bundle and Simple Products</title>
                    </cleanlink>
                </methods>
            </bundle_link>
        </resources>
        <resources_alias>
            <pacote>bundle_link_pacote</pacote>
        </resources_alias>
        <v2>
            <resources_function_prefix>
                <bundle_link>pacote</bundle_link>
            </resources_function_prefix>
        </v2>
    </api>
</config>

Wsdl.xml:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
         xmlns="http://schemas.xmlsoap.org/wsdl/"
         name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
</types>
<message name="pacoteCreatelinkRequest">
    <part name="sessionId" type="xsd:string"/>
    <part name="message" type="xsd:string" />
</message>
<message name="pacoteCreatelinkResponse">
    <part name="result" type="xsd:string" />
</message>
<portType name="{{var wsdl.handler}}PortType">
    <operation name="pacoteCreatelink">
        <documentation>Create Link to Bundle Products</documentation>
        <input message="typens:pacoteCreatelinkRequest" />
        <output message="typens:pacoteCreatelinkResponse" />
    </operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="pacoteCreatelink">
        <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
        <input>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </input>
        <output>
            <soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </output>
    </operation>
</binding>
<service name="{{var wsdl.name}}Service">
    <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
        <soap:address location="{{var wsdl.url}}" />
    </port>
</service>
</definitions>

Config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Company_Bundleapi>
            <version>0.1.0</version>
        </Company_Bundleapi>
    </modules>
    <global>
        <models>
            <bundleapi>
                <class>Company_Bundleapi_Model</class>
            </bundleapi>
        </models>
    </global>
</config>

Я проверял это и это раньше.

Author: Community, 2014-09-08

2 answers

Как вы подключились через api? Если значение выглядит как http://example.com/api/soap?wsdl тогда вы все еще звоните в V1. Обновите его, чтобы он выглядел так http://example.com/api/v2_soap/?wsdl

Также, пожалуйста, не забудьте обновить системный кэш.

Если вы хотите предотвратить кэширование в будущем, используйте:

ini_set("soap.wsdl_cache_enabled", 0);

Или динамически:

$client = new SoapClient('http://somewhere.com/?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
 5
Author: , 2014-09-09 02:34:53

Проблема resources_function_prefix тег, в api.xml . Это отвечает за указание префикса вызова в формате v2 для API ресурсов v1. Я использовал его неправильно.

Мой текущий api.xml:

<?xml version="1.0"?>
<config>
<api>
    <resources>
        <blink translate="title" module="company_bundleapi">
        <title>Create Bundle link</title>
        <model>bundleapi/pacote_api</model>
        <methods>
            <createlink translate="title" module="company_bundleapi">
                <title>Create link Options Bundle</title>
            </createlink>
            <cleanlink translate="title" module="company_bundleapi">
                <title>Clean link beetwen Bundle and Simple Products</title>
            </cleanlink>
        </methods>
        </blink>
    </resources>
    <v2>
        <resources_function_prefix>
            <blink>blinkBlink</blink>
        </resources_function_prefix>
    </v2>
</api>
</config>

Вызов в API V2: $result = $client->blinkBlinkCreatelink($session,'string');

Для получения дополнительной информации: http://alanstorm.com/magento_soap_v2_adapter

 1
Author: Denis Spalenza, 2014-09-09 04:47:01