Magento API v2 PHP错误
我正尝试在C#中使用SOAP。 Magento 1.4.2。Magento API v2 PHP错误
http://localhost/api/v2_soap/?wsdl
在这里我可以看到该方法catalogProductCreate
所以我尝试使用连接:
$proxy = new SoapClient('http://localhost/api/v2_soap/?wsdl');
$sessionId = $proxy->login('xxx', 'xxxxxx'); // user with full access
$newProductData = new stdClass();
$newProductData->name = 'Product Name';
$newProductData->description = 'Description';
$newProductData->short_description = 'Short Description';
$newProductData->websites = array(138);
$newProductData->categories = array(7,15);
$newProductData->status = 1;
$newProductData->price = 45;
$newProductData->tax_class_id = 2;
$newProductData->weight = 1;
$result = $proxy->catalogProductCreate(
$sessionId, // Soap Session
'simple', // Product Type
4, // Attribute Set Id (Default)
'product-sku', // Product Sku
$newProductData // Product Data
);
但我收到这样的输出:
Fatal error: Uncaught SoapFault exception: [4] Resource path is not callable.
确保您能她的WSDL资源是正确的,但我也遇到了这个问题,当我没有用户设置直到角色的正确权限。
(细节具体Magento的1.6.x版,但技巧,如果没有细节,应适用于其他版本)
我假设的基础上,您的代码示例,您使用的是PHP客户端代码测试方法的存在性,然后您可以将其应用于C#应用程序的调用?
假设是这样,这意味着你知道PHP,所以你需要在Magento soap服务器PHP级别进行调试。唯一的类文件产生故障
app/code/core/Mage/Api/Model/Server/Handler/Abstract.php
不管是临时的,直接添加以下记录到该文件,或在
app/code/local/Mage/Api/Model/Server/Handler/Abstract.php
下降的类文件的拷贝,codepool覆盖。
看在类文件以下异常
throw new Mage_Api_Exception('resource_path_not_callable')
这是Magento的SOAP服务器是什么原因引起来的响应与故障。这个文件中有四个地方发生。在每个之上添加日志记录调用。
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
这会让你知道哪个故障导致你的问题,从中你可以进一步调试和记录。有两个地方可能发生(文件中共有四个,一个用于常规呼叫,另一个用于多路呼叫)。
按照出现的顺序,在评论中可能的原因。
//here magento is attempting to instantiate the "API Model" that will perform
//the work of your API call. Upon instantiation, it discovers that the model
//doesn't inherit from Mage_Api_Model_Resource_Abstract, and bails.
//This is rare for a non-custom API call, but might be caused by a class rewrite
//gone amuck, or a very hacked system
try {
$model = Mage::getModel($modelName);
if ($model instanceof Mage_Api_Model_Resource_Abstract) {
$model->setResourceConfig($resources->$resourceName);
}
} catch (Exception $e) {
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
}
//Here Magento's been able to instantiate the $model, and is checking if the method is
//callable. If not, it bails. Again, for a standard, stock API call this shouldn't
//be happening, but could be the result of a rewrite gone wrong, or someone hacking an
//api class to make the method non accesible, or someone hacking the method mapping in api.xml
if (is_callable(array(&$model, $method))) {
if (isset($methodInfo->arguments) && ((string)$methodInfo->arguments) == 'array') {
return $model->$method((is_array($args) ? $args : array($args)));
} elseif (!is_array($args)) {
return $model->$method($args);
} else {
return call_user_func_array(array(&$model, $method), $args);
}
} else {
Mage::Log(sprintf('Line %s in file %s',__LINE__, __FILE__));
throw new Mage_Api_Exception('resource_path_not_callable');
}
找出Magento为什么会抛出API错误。它会经常指向你的肥皂呼叫中的一个类型,或者指向你在PHP系统中被黑掉的东西
把这个文件放到magento/project的根文件夹中,这样你就可以访问magento的所有方法。
享受的想法...
尝试创建与角色的web服务的用户,并将它们分配给访问“ALL”的作用。角色信息中角色资源菜单中的选项。
错误的哪个部分你不完全明白吗?你能详细说明吗? – hakre 2011-12-15 13:42:12
http:// localhost/api/v2_soap /?wsdl在浏览器中打开它看看是否有这样的方法catalogProductCreate – 2011-12-15 13:53:48