Magento自定义方法API V2不是此服务的有效方法

时间:2014-09-08 07:58:11

标签: api magento soap wsdl

我为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>

我之前检查过thisthisthis

1 个答案:

答案 0 :(得分:1)

尝试在api.xml中添加“v2”部分,如下所示:

   <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的<resources>部分中定义)。