How to configure custom api for Magento using SOAP V2?

I am on Magento 1.4.1.1, and I am trying to configure a custom function in an API using SOAP v2. It works for me for SOAP v1, but I need v2 so that C # can use it. For v2, the function is displayed in WSDL, but alwasy returns this error: The procedure "testFoo" is missing.

Here are my files:

/app/etc/modules/ABT_Test.xml

<?xml version="1.0"?> <config> <modules> <ABT_Test> <active>true</active> <codePool>local</codePool> </ABT_Test> </modules> </config> 

/app/code/local/ABT/Test/etc/config.xml

 <?xml version="1.0"?> <config> <modules> <ABT_Test> <active>true</active> <codePool>local</codePool> <version>1.0</version> </ABT_Test> </modules> <global> <models> <test> <class>ABT_Test_Model</class> </test> </models> </global> </config> 

/app/code/local/ABT/Test/etc/api.xml

 <?xml version="1.0"?> <config> <api> <resources> <test> <model>test/api</model> <title>ABT Test Api</title> <methods> <foo translate="title" module="test"> <title>Foo Test</title> <method>foo</method> <acl>test/foo</acl> </foo> </methods> </test> </resources> <v2> <resources_function_prefix> <test>test</test> </resources_function_prefix> </v2> </api> </config> 

/app/code/local/ABT/Test/etc/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="testFooRequest"> <part name="sessionId" type="xsd:string" /> </message> <message name="testFooResponse"> <part name="result" type="typens:boolean" /> </message> <portType name="{{var wsdl.handler}}PortType"> <operation name="testFoo"> <documentation>Test Foo</documentation> <input message="typens:testFooRequest" /> <output message="typens:testFooResponse" /> </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="testFoo"> <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> </definitions> 

/app/code/local/ABT/Test/Model/API.php

 <?php class ABT_Test_Model_Api extends Mage_Api_Model_Resource_Abstract { public function foo() { return true; } } ?> 

/app/code/local/ABT/Test/Model/API/V2.php

 <?php class ABT_Test_Model_Api_V2 extends ABT_Test_Model_Api { } ?> 

And here is the code I use to test the API:

 <?php $mageUser = '########'; $mageApiKey = '########'; //SOAP V1 echo "SOAP V1 <br />"; $mageUrl = 'http://www.########.com/api/soap/?wsdl'; $soap = new SoapClient($mageUrl, array('cache_wsdl' => 0)); try { $sessionID = $soap->login($mageUser, $mageApiKey); var_dump($soap->call($sessionID, 'test.foo', array())); } catch (Exception $e) { echo 'Exception: ' . $e->getMessage() . '<br />'; } //SOAP V2 echo "SOAP V2 <br />"; $mageUrl2 = 'http://www.########.com/api/v2_soap/?wsdl'; $soap2 = new SoapClient($mageUrl2, array('cache_wsdl' => 0)); try { $sessionID2 = $soap2->login($mageUser, $mageApiKey); var_dump($soap2->testFoo($sessionID2)); } catch (Exception $e) { echo 'Exception: ' . $e->getMessage() . '<br />'; } ?> 

I closed the username, password and URL. The function is displayed in v2 WSDL, and the php code recognizes that it is in WSDL, but I still get the error: the procedure "testFoo" is missing.

So what am I missing?

EDIT: I did what Zyav suggested, and he got my example. Then I copied the folder and did an exact (case sensitive) search and replace to use the meaningful name and module name. I was careful to choose names that I thought would not be backup words. In the new module, the WSDL call v1 works fine, but v2 gives the same message "Procedure" xxx "no." Then I sent and renamed the method in the test from "Foo" to "Fooz", and I received this message: "The path to the resource is not called." I am wondering if I am receiving another message. This makes me think that there is some cache / configuration / something that is causing the problem. Any ideas?

+4
source share
3 answers

First I must warn you that Magento does not currently support the SOA v2 format, api / v2_soap /? wsdl is just the second version of soap api .

1.

 <models> <test> <class>ABT_Test_Model</class> </test> </models> 

Since you are writing a module that is not a kernel, you must write <abt_test>

2. <model>test/api</model> . In your case there should be <model>abt_test/api</model> .

3. <acl>test/foo</acl> .

Does this acl section exist in your adminhtml.xml?

+2
source

bygrace,

your code is so perfect!

add

 .... <resources_alias> <test>test</test> </resources_alias> ..... 

same level with

 <resources> and <v2> 

on api.xml

and it will work well.

+1
source

I have the same problem and I tried to clear the tmp file, because I placed it using xampp, it did not work, I got Procedure not present exception , I had to disable cache management on the server administration page .
How to disable cache on admin page
On the administration page in the system there is a section called cache management, which disables everything at the development stage or any changes that you will not reflect in wsdl.

0
source

All Articles