我试图创建一个肥皂服务,但不知何故它的wsdl url不起作用。以下是代码:-Api/CustomapitInterface.php
namespace W3solverCustomapiApi;
interface CustomapiInterface
{
/**
* Returns greeting message to user
*
* @api
* @param string $name Users name.
* @return string Greeting message with users name.
*/
public function name($name);
}
型号/自定义.php
<?php
namespace W3solverCustomapiModel;
use W3solverCustomapiApiCustomapiInterface;
class Customapi implements CustomapiInterface
{
/**
* Returns greeting message to user
*
* @api
* @param string $name Users name.
* @return string Greeting message with users name.
*/
public function name($name) {
return "Hello, " . $name;
}
}
等等/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="W3solverCustomapiApiCustomapiInterface" type="W3solverCustomapiModelCustomapi" />
</config>
等/模块.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="W3solver_Customapi" setup_version="1.0.0" />
</config>
等等/网络.xml
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/customapi/name/:name" method="GET">
<service class="W3solverCustomapiApiCustomapiInterface" method="name"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
我通过使用 http://inchoo.net/magento/api-magento/magento-2-custom-api/的引用创建了它。我没有错在哪里。
以下是我尝试使用的网址:-http://magento2.local/index.php/soap/default?wsdl&services=w3solverCustomapiV1
Magento 2默认禁用对匿名API的API访问,您需要从后端管理面板启用此功能。
要禁用此功能,请登录到管理面板并选择
存储>配置>服务>Magento Web API>Web API Security。
然后从"允许匿名来宾访问"菜单中选择"是"。
可以在此处找到有关开发指南的详细信息。