How to call the Magento API from VB.NET

Function getHTTPStream() As String
    Dim myh As HttpWebRequest = _
    HttpWebRequest.Create("http://yourmagentoweb/soap/api/?wsdl")
    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

That code needs tweaking obviously- i have not got time to prettify this stuff


from Abid Hussain’s link

1. Using wdsl tool I created a .vb source file by calling:

wsdl /language:VB /out:MageProxyClass.vb http:///api/v2_soap?wsdl

2. Afterwards I used the VB Comand Line Editor to compile the sourcefile into a dll.

vbc /out:MageProxyClass.dll /t:library
/r:System.XML.dll,System.Web.Services.dll MageProxyClass.vb

3. Finally I was able to create an instance of MagentoService class defined in my MageProxyClass.dll

Private WithEvents msvc As New MagentoService() 

4. Example:

 Public Class main
    Private WithEvents msvc As New MagentoService()
    Private ssid As String
    Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        ListBox1.Items.Add("Trying to connect")
        msvc.loginAsync("xxxx", "xxxxxxxxxxxxxxxx")
    End Sub

    Public Sub MageLoginComplete(ByVal sender As System.Object, ByVal e As loginCompletedEventArgs) Handles msvc.loginCompleted
        ListBox1.Items.Add("Login completed")
        ssid = e.Result
        ListBox1.Items.Add(String.Concat("Session ID: ", ssid))
    End Sub
End Class 

Leave a Comment