【问题标题】:Magento Custom method API V2 is not a valid method for this serviceMagento 自定义方法 API V2 不是此服务的有效方法
【发布时间】:2014-09-08 07:58:10
【问题描述】:

我为 Magento SOAP API 创建了一个自定义方法,到目前为止它运行良好。现在我想为 Magento SOAP API V2 创建相同的方法。

我创建了 WSDL.xml 和 V2.php 类文件(如下),当我尝试在 V2 API 中调用我的方法时,我收到了这个错误:

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>
    </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>

我之前检查过this、this 和this。

【问题讨论】:

    标签: api magento soap wsdl


    【解决方案1】:

    尝试将“v2”部分添加到您的 api.xml,如下所示:

       <config>
          <api>
             <resources>
                ...
             </resources>
             <v2>
                <resources_function_prefix>
                   <bundle_link>pacote</bundle_link>
                </resources_function_prefix>
             </v2>
          </api>
       </config>
    

    这告诉 Magento API 适配器,以“pacote”开头的调用指的是资源“bundle_link”中的方法(您已经在 api.xml 的 &lt;resources&gt; 部分定义了)。

    【讨论】:

    • 另外一件事:检查您的 API 客户端是否没有缓存 WSDL。我花了几天的时间来解决“不是此资源的有效方法”错误,最终发现我的模块很好,它只是 PHP 缓存。 GRRR。 SoapClient 构造函数接受一个选项数组,确保在开发过程中将 cache_wsdl 设置为 WSDL_CACHE_NONE。
    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多