HostedShop Help | API

Dansk English

3. .NET examples

For easy access to  the HostedShop API from a .NET environment you can use our precompiled .NET Proxy. It can be downloaded from https://api.hostedshop.dk/HostedShop.dll

For at tilgå HostedShop API fra et .NET miljø kan man med fordel tage vores .NET proxy i brug. Den kan hentes fra . The proxy requires the System.Web.Services library to be included in the project to run.

The following example prints out a list of products and their variants in the console:

using System;
using HostedShop;
 
class Program
{
    static void Main(string[] args)
    {
        /* Create a new proxy object */
        Webservice Client = new Webservice();
 
/* Create a cookieContainer for the proxy object. This is necassary because the Webservice is session-based */
        Client.CookieContainer = new System.Net.CookieContainer();
 
        /* Create a connection to a solution */
        Client.Solution_Connect("brugernavn", "password");
 
        /* Set the language for the solution */
        Client.Solution_SetLanguage("UK");
 
        /* Set the wanted fields for the Product object */
        Client.Product_SetFields("Id,Title,Variants");
 
        /* Set the wanted fields for the ProductVariant object */
        Client.Product_SetVariantFields("Id");
 
        /* Fetch all products */
        Product[] result = Client.Product_GetAll();
 
        /* Loop the products */
        foreach (Product product in result)
        {
            /* Print the product title */
            Console.WriteLine("Produkt: " + product.Title);
 
            if (product.Variants.Length > 0)
            {
                Console.Write("Varianter:");
 
                /* Loop the products variants */
                foreach (ProductVariant variant in product.Variants)
                {
                   
                    /* Fetch the variants TypeValues */
                    ProductVariantTypeValue[] variantTypeValues = Client.Product_GetVariantTypeValues(variant.Id);
 
/* Loop the variants TypeValues and print their title */
                    foreach (var variantTypeValue in Client.Product_GetVariantTypeValues(variant.Id))
                    {
                        Console.Write(" " + variantTypeValue.Title);
                    }
                    Console.WriteLine("");
                }
            }
        }
    }
}

Notice that the proxy automatically wraps arguments and dewraps return arguments.

The proxy has been generated using the native .NET wsdl to proxy generator, using the https://api.hostedshop.dk/service.wsdl.

IF you prefer using another proxy, several tools for creating a proxy from a SOAP document / literal wrapped WSDL exist.

Please refer to section 2 or the complete documentation at https://api.hostedshop.dk/doc/ for a more detailed description of the various functionalities of the API.