How to call the Magento API from VB.NET

How to call the Magento API from VB.NET

July 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to call the Magento API from VB.NET

Solving the Magento API Call from VB.NET Challenge

Calling the Magento API from VB.NET can indeed be challenging due to compatibility issues between versions. In this guide, I’ll walk you through a step-by-step process to successfully make an API call and retrieve results using VB.Net in your Visual Studio 2010.

Understanding the Error: Unable to Import WebService/Schema

The error message suggests that there is a syntax mismatch between the operation name in the binding section and the port type section of the WSDL file. This typically occurs when the API version you’re trying to connect to is not compatible with your current Magento setup (1.7.0.2).

Resolving the Error: A VB.NET Solution

To resolve this issue, we need to ensure that the web service settings are correctly configured and that the WSDL file is compatible with our VB.NET application.

Step 1: Configure the Magento API

Firstly, let’s make sure you have set up the SOAP API in your Magento store:

  1. Log in to your Magento admin panel.
  2. Navigate to System > Web Services > SOAP XML-RPC - Service Settings.
  3. Set the ‘Webservices Configuration’ option to ‘Yes’.
  4. Save the changes.

Step 2: Generate and Download the WSDL File

Next, you need to generate a WSDL file that is compatible with your VB.NET application:

  1. In your browser’s address bar, enter the following URL, replacing your_magento_url with your actual Magento store URL:

    http://your_magento_url/index.php/api/v2_soap?wsdl
    
  2. Download the WSDL file.

Step 3: Add a Service Reference in VB.NET

Now let’s add this WSDL as a service reference to your VB.NET project:

  1. In Visual Studio, right-click on your project and select “Add > Service Reference”.
  2. Click “Advanced…”.
  3. Type http://your_magento_url/index.php/api/v2_soap?wsdl in the ‘Service URL’ field.
  4. Select the checkbox for “Reuse types in referenced assemblies”.
  5. Click “OK”.

Making a Successful API Call

Once you’ve added the service reference, you can create an instance of the Magento SOAP client and call methods like catalogProductAttributeRemove.

Step 1: Create the Service Client

Imports System.Web.Services.Protocols
Imports System.Net.Security

' ... Other necessary imports ...

Public Class MageSoapClient
    Inherits SoapHttpClientProtocol

    Public Sub New()
        Me.Address = New Uri("http://your_magento_url/index.php/api/v2_soap?wsdl")
        Me.Credentials = New NetworkCredential("username", "password")  ' Replace with your Magento API credentials
    End Sub
End Class

Step 2: Create a Session and Call the Method

Public Function RemoveProductAttribute(ByVal client As MageSoapClient)
    Dim result As Object = Nothing

    Try
        ' Initialize session
        client.Open()

        ' Create a new session to Magento API
        Dim loginResponse As New Mage_Api_Model_Server_V2_LoginResponse()
        loginResponse = CType(client.GetMethod("login", New Object() {"username", "password"}), Mage_Api_Model_Server_V2_LoginResponse)

        If Not IsNothing(loginResponse) AndAlso loginResponse.ResultCode = 0 Then
            ' Create a new session to Magento API
            Dim removeResult As New Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_RemoveResponse()
            removeResult = CType(client.GetMethod("catalogProductAttributeRemove", New Object() {
                "sessionId": loginResponse.SessionId,
                "attribute_id": 0 ' Replace with the actual attribute ID
            }), Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_RemoveResponse)

            result = removeResult.Result
        End If

    Catch ex As Exception
        Console.WriteLine(ex.Message)
    Finally
        client.Close()
    End Try

    Return result
End Function

Conclusion: Successfully Connecting VB.NET to Magento API

By following these steps and ensuring you’re using the correct WSDL file, you should be able to successfully connect your VB.NET application to the Magento SOAP API and execute methods like catalogProductAttributeRemove.

Remember that the specific method names and parameters may vary depending on the version of Magento you’re working with. Always refer to the official Magento documentation for the most up-to-date information.

If you find yourself struggling with API integration, consider reaching out to professionals at Laravel Company, who specialize in custom development and can provide expert guidance tailored to your specific needs.

Happy coding!

Magento 1 API Admin Configuration

Our network