首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是PHP Soaps multiCall等同于Magento API v2的.NET调用

什么是PHP Soaps multiCall等同于Magento API v2的.NET调用
EN

Stack Overflow用户
提问于 2011-08-26 14:00:19
回答 1查看 1.2K关注 0票数 1

我很高兴地将一个端点连接到我的.NET项目中,创建了包装器类,一切都很容易。(我使用PHP教程尽可能多地进行翻译),然后我遇到了一个巨大的瓶颈,我真的不知道如何解决。我找不到任何关于这方面的好消息。

所以..。

在PHP中,我可以使用

代码语言:javascript
复制
$calls = array( 
    array( 'catalog_product.info', 166 ), 
    array( 'catalog_product.info', 167 ), 
    array( 'catalog_product.info', 168 ), 
); 
$results = $soap->multiCall( $session_id, $calls ); 

在一次调用中,我将获得3个产品,从而节省了70%的http开销。

在.NET中,我使用以下代码

代码语言:javascript
复制
   Dim productReturn As MS.catalogProductReturnEntity
   Private myMagento As MS.Mage_Api_Model_Server_V2_HandlerPortType = New MS.Mage_Api_Model_Server_V2_HandlerPortTypeClient
   productReturn = myMagento.catalogProductInfo(SessionID, productId, storeView, requestAttr, Nothing)

这将返回一项扩展信息。.NET中的服务引用

代码语言:javascript
复制
Function catalogProductInfo(ByVal sessionId As String, ByVal product
As String, ByVal storeView As String, ByVal attributes As
MagentoBridge2.MS.catalogProductRequestAttributes, ByVal
productIdentifierType As String) As
MagentoBridge2.MS.catalogProductReturnEntity
Member of MagentoBridge2.MS.Mage_Api_Model_Server_V2_HandlerPortType

不接受一系列产品..

那么,在.NET中如何使用multiCall呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-26 23:49:44

单击>Some more details here

您需要将一个PHP文件放在magento服务器的根目录下,如下所示

代码语言:javascript
复制
<?php
$id_start = $_GET['start'];
$id_end = $_GET['end'];

// Magento login information 
$mage_url = 'http://www.YOURSITE.co.uk/api/?wsdl=1'; 
$mage_user = 'USERNAME'; 
$mage_api_key = 'PASSWORD'; 

// Initialize the SOAP client 
$soap = new SoapClient( $mage_url ); 

// Login to Magento 
$session_id = $soap->login( $mage_user, $mage_api_key );

    $calls = array(); 
    for ($id_start; $id_start <= $id_end; $id_start++)
        {
        array_push($calls, array( 'catalog_product.info', $id_start ));
        }

    $results = $soap->multiCall( $session_id, $calls ); 

    echo json_encode($results);
?>

正确的!简单!然后在.NET中,你有一个很好的函数,如下所示!

代码语言:javascript
复制
Function getHTTPStream() As String
        Dim myh As HttpWebRequest = HttpWebRequest.Create("http://www.YOURSITE.co.uk/prod.php?start=20&end=80")
        myh.Timeout = 30000
        myh.UserAgent = "Test"
        Dim myR As HttpWebResponse = myh.GetResponse()
        Dim myEnc As Encoding = Encoding.GetEncoding(1252)
        Dim mySr As StreamReader = New StreamReader(myR.GetResponseStream(), myEnc)

        Return mySr.ReadToEnd()
    End Function

请注意,我传递了start=20;这是它将开始的ID和end=80

TADAAAAAAAAAAAAAAAAAAAAAa..

现在,您在.NET中所需要做的就是将JSON转换为一个表。例如,使用THIS,你知道吗!我现在可以在Visual Studio的.NET!Whoooooooooohoooooooooo!!中每秒请求大约100个产品的完整扩展信息,而在多线程请求中,我花了每秒3个产品的时间进行单独的调用。多大的进步啊。

感谢大家的帮助。(远处的知更鸟)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7200558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档