新的 Magento API 方法 WS-I 错误

问题描述 投票:0回答:1

这是我的第一篇文章,所以如果我让事情变得更混乱,我很抱歉......

我正在尝试在 Magento 1.8 中创建一个新的 API 方法,以便允许将简单产品分配给捆绑产品。我遵循了一些不同的指南,但每个示例都给了我相同的错误:

SoapFault Object
(
    [message:protected] => Function ("blinkAssign") is not a valid method for this service
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => C:\wamp\www\customer\sincro\test.php
    [line:protected] => 27
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => C:\wamp\www\customer\sincro\test.php
                    [line] => 27
                    [function] => __call
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => blinkAssign
                            [1] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [sessionId] => fe0b90725878bf1e8fac34ebf7a64137
                                            [message] => test
                                        )

                                )

                        )

                )

            [1] => Array
                (
                    [file] => C:\wamp\www\customer\sincro\test.php
                    [line] => 27
                    [function] => blinkAssign
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [sessionId] => fe0b90725878bf1e8fac34ebf7a64137
                                    [message] => test
                                )

                        )

                )

        )

    [previous:Exception:private] => 
    [faultstring] => Function ("blinkAssign") is not a valid method for this service
    [faultcode] => Client
    [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)

这些是我的文件:

/Interdigital/Bundleapi/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Interdigital_Bundleapi>
            <version>0.1.0</version>
        </Interdigital_Bundleapi>
    </modules>
    <global>
        <helpers>
            <bundleapi>
                <class>Interdigital_Bundleapi_Helper</class>
            </bundleapi>
        </helpers>
        <models>
            <bundleapi>
                <class>Interdigital_Bundleapi_Model</class>
            </bundleapi>
        </models>
    </global>
</config>

/Interdigital/Bundleapi/etc/api.xml

<?xml version="1.0"?>
<config>
    <api>
        <resources>
            <bundleapi_blink translate="title" module="bundleapi">
                <title>Bundleapi</title>
                <model>bundleapi/blink_api</model>
                <acl>bundleapi/blink</acl>
                <methods>
                    <assign translate="title" module="bundleapi">
                        <title>Assign</title>
                        <acl>bundleapi/blink/assign</acl>
                    </assign>
                </methods>
            </bundleapi_blink>
        </resources>
        <resources_alias>
            <blink>bundleapi_blink</blink>
        </resources_alias>

        <v2>
            <resources_function_prefix>
                <blink>blink</blink>
            </resources_function_prefix>
        </v2>
        <acl>
            <resources>
                <bundleapi translate="title" module="bundleapi">
                    <title>Bundleapi</title>
                    <sort_order>1</sort_order>
                    <blink translate="title" module="bundleapi">
                        <title>Blink</title>
                        <sort_order>2000</sort_order>
                        <assign translate="title" module="bundleapi">
                            <title>Assign</title>
                        </assign>
                    </blink>
                </bundleapi>
            </resources>
        </acl>
    </api>
</config>

/Interdigital/Bundleapi/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="blinkAssignRequest">
        <part name="sessionId" type="xsd:string"/>
        <part name="message" type="xsd:string" />
    </message>
    <message name="blinkAssignResponse">
        <part name="result" type="xsd:string" />
    </message>
    <portType name="{{var wsdl.handler}}PortType">
        <operation name="blinkAssign">
            <documentation>this is an example of api method...</documentation>
            <input message="typens:blinkAssignRequest" />
            <output message="typens:blinkAssignResponse" />
        </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="blinkAssign">
            <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>

/Interdigital/Bundleapi/模型/Blink/Api.php

<?php
class Interdigital_Bundleapi_Model_Blink_Api extends Mage_Api_Model_Resource_Abstract
{
    public function assign($message)
    {
        return "This is the message: ".$message;
    }
}

/Interdigital/Bundleapi/模型/Blink/Api/V2.php

<?php
class Interdigital_Bundleapi_Model_Blink_Api_V2 extends Interdigital_Bundleapi_Model_Blink_Api
{
    //empty
}

我在 /etc 中也有 wsi.xml 文件,但它与 wsdl.xml 相同,但将 wsdl: 添加到标签中...

我这样打电话:

$proxy = new SoapClient('http://local.domain/api/v2_soap/?wsdl');
$sessionId = $proxy->login((object)array('username' => 'interdigital', 'apiKey' => 'pruebaeltaller'));
try{
    $resultretun = $proxy->blinkAssign((object)array('sessionId' => $sessionId->result, 'message' => 'test'));
}catch(SoapFault $e){
    echo "<pre>";print_r($e);echo "</pre>";
}
print_r($resultretun);
$proxy->endSession((object)array('sessionId' => $sessionId->result));

我将不胜感激任何形式的帮助,因为这让我发疯......谢谢!

magento soap wsdl magento-1.8 magento-soap-api
1个回答
0
投票

OP 的解决方案。

我发现了问题......它与 wsi.xml 文件有关,所以我粘贴在这里工作的文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl: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/"
                  name="{{var wsdl.name}}"
                  targetNamespace="urn:{{var wsdl.name}}">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:{{var wsdl.name}}">
            <xsd:element name="blinkAssignRequestParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />
                        <xsd:element minOccurs="1" maxOccurs="1" name="message" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="blinkAssignResponseParam">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="blinkAssignRequest">
        <wsdl:part name="parameters" type="typens:blinkAssignRequestParam"/>
    </wsdl:message>
    <wsdl:message name="blinkAssignResponse">
        <wsdl:part name="parameters" type="typens:blinkAssignResponseParam" />
    </wsdl:message>
    <wsdl:portType name="{{var wsdl.handler}}PortType">
        <wsdl:operation name="blinkAssign">
            <wsdl:documentation>API method assign products to bundle</wsdl:documentation>
            <wsdl:input message="typens:blinkAssignRequest" />
            <wsdl:output message="typens:blinkAssignResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="blinkAssign">
            <soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="{{var wsdl.name}}Service">
        <wsdl:port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
            <soap:address location="{{var wsdl.url}}" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
© www.soinside.com 2019 - 2024. All rights reserved.