FEEDBACK
X
FEEDBACK

Er du tilfreds med indholdet i denne her guide?

Hvis ikke, så vil vi meget gerne høre dine kommentarer.

Skriv dem herunder, så gør vi det bedste, vi kan for at forbedre manualen.

Tak for din kommentar!

Send ny?

Dansk English

SmartWeb Help | API

3. .NET examples

To access the SmartWeb API from a .NET environment, you can easily add the WSDL file as a proxy client in Visual Studio using this guide.

1. Add a "Service Reference" to your project:

2. Type the URL to the WSDL file in the "address" field, then click the "Go" button. The URL is: https://api.smart-web.dk/service.wsdl

3. You should be able to see the class WebServicePort in the left column and all the available methods for the API in the right column:

4. Type a name for your new reference in the section "Namespace". In this case we are refering to it by the name "WebService". Click OK.

5. Open the file "App.Config" in your project in Visual Studio and find the binding named "WebServiceBinding". In this binding you should type a new attribute called allowCookies="true". This allows the proxy client to save the session in the API as a cookie. The code should look like this when you are done:
 

 
<binding name="WebServiceBinding" allowCookies="true">
    <security mode="Transport" />
</binding>
 

6. Use the following example to output a list of products and their variants for a given SmartWeb solution in the .NET console. In the example we are refering to the proxy client under the name "ConsoleApplication1.WebService". If you don't have a specific API user, you can fall back to your general login details for the solution.

using System;
using ConsoleApplication1.WebService; /* Our project is named "ConsoleApplication1", but you should refer to your own default namespace here */
 
class Program
{
    static void Main(string[] args)
    {
        /* Create a new proxy object */
        Webservice Client = new WebservicePortClient();
 
        /* Create a connection to a solution */
        Client.Solution_Connect("username", "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 https://api.smart-web.dk/service.wsdl.

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