Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用SOAP V2为Magento设置自定义api?_C#_Php_Web Services_Magento_Soap - Fatal编程技术网

C# 如何使用SOAP V2为Magento设置自定义api?

C# 如何使用SOAP V2为Magento设置自定义api?,c#,php,web-services,magento,soap,C#,Php,Web Services,Magento,Soap,我使用的是Magento 1.4.1.1,我正在尝试使用SOAP v2在API中设置自定义函数。我让它为soapv1工作,但我需要v2以便C#可以使用它。对于v2,函数显示在WSDL中,但alwasy返回以下错误:过程“testFoo”不存在 这是我的档案: /app/etc/modules/ABT_Test.xml <?xml version="1.0"?> <config> <modules> <ABT_Test>

我使用的是Magento 1.4.1.1,我正在尝试使用SOAP v2在API中设置自定义函数。我让它为soapv1工作,但我需要v2以便C#可以使用它。对于v2,函数显示在WSDL中,但alwasy返回以下错误:过程“testFoo”不存在

这是我的档案:

/app/etc/modules/ABT_Test.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
        </ABT_Test>
    </modules>
</config>
<?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>
<?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>
<?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/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
        </ABT_Test>
    </modules>
</config>
<?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>
<?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>
<?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>

真的
地方的
1
ABT_测试_模型
/app/code/local/ABT/Test/etc/api.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
        </ABT_Test>
    </modules>
</config>
<?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>
<?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>
<?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>

测试/空气污染指数
测试Api
Foo试验
福
测试/食物
测试
/app/code/local/ABT/Test/etc/wsdl.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ABT_Test>
            <active>true</active>
            <codePool>local</codePool>
        </ABT_Test>
    </modules>
</config>
<?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>
<?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>
<?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;
    }
}
?>
<?php
class ABT_Test_Model_Api_V2 extends ABT_Test_Model_Api
{
}
?>

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

<?php
class ABT_Test_Model_Api extends Mage_Api_Model_Resource_Abstract
{

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

下面是我用来测试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 />';
    }
?>

我模糊了用户名、密码和url。该函数显示在v2wsdl中,php代码识别它在WSDL中,但我仍然得到错误:过程“testFoo”不存在

那么我错过了什么

编辑:
我按照Zyava的建议做了,这让我的榜样起了作用。然后我复制了文件夹,并进行了精确(区分大小写)的查找和替换,以使用有意义的模块名和函数名。我小心翼翼地挑选了一些我认为不会成为保留词的名字。在新模块上,对v1wsdl的调用工作正常,但v2给出了相同的“Procedure'xxx'notpresent”消息。然后,我将测试中的方法从'Foo'重命名为'Fooz',我得到了这样一条消息:“资源路径不可调用。”我发现有趣的是,我得到了一条不同的消息。这让我相信是缓存/配置/某些东西导致了问题。有什么想法吗

首先,我应该警告您,Magento目前不支持SOAP v2格式,api/v2\u SOAP/?wsdl只是一个例子

一,


ABT_测试_模型
因为您编写的模块不是核心模块,所以应该编写

2.
测试/api
。在您的情况下,应该是
abt\u测试/api

3.
test/foo

您的adminhtml.xml中是否存在此acl部分?

bygrace

你的代码太完美了

。。。。
测试
.....
同级

<resources> and <v2>
关于Api.xml


它会很好地工作。

我也遇到了同样的问题,我尝试清除tmp文件,因为我使用xampp托管了它。它不起作用。我得到了
过程ББ.不存在异常
,我必须在服务器的管理页面中禁用缓存管理
如何在管理页面中禁用缓存

在系统下的管理页面中有一个名为“缓存管理”的部分,在开发阶段禁用所有内容,否则您所做的任何更改都不会反映在wsdl中。

对不起,您的建议确实有效,但我遇到了缓存问题。问题是服务器上的PHP WSDL缓存。我必须添加以下内容:
ini_集('soap.wsdl_缓存已启用,'0')
@Zyava我不明白,为什么要使用abt_test/api而不是test/api?As“测试”被定义为ABT_测试_模型。为什么仍然需要包含包名?对于非核心模块来说,最好的做法是在任何地方都使用完整的模块名(带包名)。