开发者

What is PHP Soaps multiCall equivalent to .NET call for Magento API v2

开发者 https://www.devze.com 2023-03-31 11:16 出处:网络
I happily connected an endpoint into my .NET project, made wrapper classes and everything is lovely jubbly..(i translated as much as possible using PHP tutorials) and i ran into a massive bottleneck t

I happily connected an endpoint into my .NET project, made wrapper classes and everything is lovely jubbly..(i translated as much as possible using PHP tutorials) and i ran into a massive bottleneck that i am not really sure how to solve.. i cant ffind any decent information about this.

So....

In PHP i can use

$calls = array( 
    array( 'catalog_product.info', 166 ), 
    array( 'catalog_product.info', 167 ), 
    array( 'catalog_product.info', 168 ), 
); 
$results = $soap->multiCall( $session_id, $calls ); 

and in one call i will get 3 products saving me like 70% http overhead.

In .NET i use this

   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)

and that returns one single item of extended information. The Service refence in .NET

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

Does not accept an array of products..

So how in .NET do use the multiCall that is used in the PHP?


CLICK >Some more details here

You need to put a PHP file on the root of your magento server that looks simething like this

<?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);
?>

Right! Simples!!!!!!!!!!!! Then in .NET you have a nice function like this!

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

Notice i pass start=20 ; That is the ID it will start at and the end=80

TADAAAAAAAAAAAAAAAAAAAAAa..

Now all you need to do in .NET is convert the JSON into a Table.. for example using THIS And you know what! I can now request full extended information on items in about 100products per second in Visual Studio Freaking .NET! Whoooooooooohoooooooooo!! Before it took me 3 products a seconds doing individual calls in multi threaded requests.. What an improvement.

Thanks for every bodies help. (Crickets in the distance)

0

精彩评论

暂无评论...
验证码 换一张
取 消