API Magento: Publier une nouvelle méthode dans le savon V2

Je suis nouveau dans Magento et j'aimerais créer mon propre API v2 méthode.
J'ai construit un projet simple...

Mycompany
    Mymodule
        etc
            api.xml
            config.xml
            wsdl.xml
        Model
            Api
                V2.php
            Api.php

Ce sont les principaux fichiers...

(1) api.xml

<config>
    <api>
        <resources>
            <mymodule translate="title" module="mymodule">
                <title>mymodule</title>
                <model>mymodule/api</model>
                <methods>                    
                    <myapimethod translate="title" module="mymodule">
                        <title>myapimethod</title>
                        <acl>mymodule/myapimethod</acl>
                    </myapimethod>
                </methods>
            </mymodule>
        </resources>
        <v2>
            <resources_function_prefix>
                <mymodule>mymodule</mymodule>
            </resources_function_prefix>
        </v2>
        <acl>
            <resources>
                <mymodule translate="title" module="mymodule">
                    <title>Mymodule</title>
                    <sort_order>2000</sort_order>                    
                    <myapimethod translate="title" module="mymodule">
                        <title>myapimethod</title>
                    </myapimethod>  
                </mymodule>
            </resources>
        </acl>
    </api>
</config>

(2) 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>
        <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
        </schema>
    </types>
    <message name="myapimethodRequest">
        <part name="sessionId" type="xsd:string"/>
        <part name="message" type="xsd:string" />
    </message>
    <message name="myapimethodResponse">
        <part name="result" type="xsd:string" />
    </message>
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="myapimethod">
            <documentation>this is an example of api method...</documentation>
            <input message="typens:myapimethodRequest" />
            <output message="typens:myapimethodResponse" />
        </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="myapimethod">
            <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>

(3) Api.php

<?php
class Mycompany_Mymodule_Model_Api extends Mage_Api_Model_Resource_Abstract
{        
        public function myapimethod($sessionId, $message)
        {
            return "This is the message : ".$message;
        }
}

(4) V2.php

<?php
class Mycompany_Mymodule_Model_Api_V2 extends Mycompany_Mymodule_Model_Api
{        

}

(5) test.php

<?php
try {
    define("SOAP_WSDL",'http://localhost:8080/magento/index.php/api/?wsdl');
    define("SOAP_WSDL2",'http://localhost:8080/magento/index.php/api/v2_soap?wsdl=1');
    define("SOAP_USER","dtsSoapUser");
    define("SOAP_PASS","casares");

    if($_GET['ver'] == '2') {
        $client = new SoapClient(SOAP_WSDL2, array('trace' => 1,'cache_wsdl' => 0));
        echo "<br>version 2 <br>";
    }
    else {
        $client = new SoapClient(SOAP_WSDL,array('trace' => 1,'cache_wsdl' => 0));

        echo "<br>version 1 <br>";
    }
    $session = $client->login(SOAP_USER, SOAP_PASS);
    $result = array();

    try {
        if($_GET['ver'] == '2') {
             $result = $client->Myapimethod($session, "My message....");
             var_dump ( $result);        
        } else {            
            $result= $client->call($session, 'mymodule.myapimethod', array($session, "My message ...."));
            var_dump($result);
        }
    } catch (SoapFault $exception) {
        echo 'EXCEPTION='.$exception;
    }

    echo "<br>end test<br>";
} catch (Exception $e){
    echo var_dump($e);
    throw $e;
}   
?>

À l'aide de l'Url suivante, le résultat est:

.../test.php/?ver=1

version 1
string 'This is the message : My message ....' (length=37)
end test

C'est-à-dire: à l'aide de Savon v1, la méthode fonctionne!.

Mais si j'utilise le savon v2 appel...

.../test.php/?ver=2
le résultat est:

version 2
EXCEPTION=SoapFault exception: [3] Invalid api path. in C:\wamp\www\PruebasPHP\test.php:22 Stack trace: #0 C:\wamp\www\PruebasPHP\test.php(22): SoapClient->__call('Myapimethod', Array) #1 C:\wamp\www\PruebasPHP\test.php(22): SoapClient->Myapimethod('b9e1e8d15a61398...', 'My message....') #2 {main}
end test

Le rôle a accès à toutes les api de ressources...

Je ne sais pas quel est le problème? quelqu'un peut-il m'aider avec ce problème?
Peut-être tout ce qui est lié à l'acl?
Merci à l'avance!!!!!

peut-être que le cache wsdl est activé ou PHP et les autres clients du cache wsdl. assurez-vous sudo rm -rf /tmp/wsdl* exécuter cette commande dans un terminal.

OriginalL'auteur Juanma R. | 2012-08-29