Skip to content

Getting Started with SIHOT@360° using .NET

Overview

In this tutorial we will be looking at the basics of the SIHOT@3060° API using the popular .NET Core environment.

For the demo purpose we will:

  • create a SOAP client from the provided WSDL
  • authenticate at the server
  • retrieve all in house guests using the API

What You Will Need

  • Internet access
  • Basic knowledge of .NET Core
  • Access to a 360° service such as public WSDL
  • .NET Core 2.1 or later (this tutorial was created using .NET 6)

The Tutorial

This tutorial will only use minimal dependencies to demonstrate the API usage. Any server components like express outputs like html are omitted to focus on the API usage itself.

Step 1 – Loading Dependencies

Initialize the project and load dependencies.

C:\src\dotnet\GettingStarted360Net6>dotnet new console
TThe template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\src\dotnet\GettingStarted360Net6\GettingStarted360Net6.csproj...
  Wiederherzustellende Projekte werden ermittelt...
  "C:\src\dotnet\GettingStarted360Net6\GettingStarted360Net6.csproj" wiederhergestellt (in "146 ms").

Restore succeeded.

After the application is initialized let's add the soap dependency.

C:\src\dotnet\GettingStarted360Net6>dotnet tool install --global dotnet-svcutil

Step 2 – Generating the SOAP client

Run the dotnet-svcutil command to generate the web service reference file as follows:

C:\src\dotnet\GettingStarted360Net6>dotnet-svcutil --sync https://partner-api.sihot.com/PDOCS/API/CBS/SihotServices01?wsdl
Microsoft (R) WCF Service Model Proxy Generation Tool for .Net Core platform
[Microsoft.Tools.ServiceModel.Svcutil, Version 2.0.2]
Copyright (c) Microsoft Corporation.  All rights reserved.

This tool collects information about how it is used in order to improve the tool. This functionality can be disabled by setting the environment variable "DOTNET_SVCUTIL_TELEMETRY_OPTOUT" to 1.

Resolving project references ...
Attempting to download metadata from 'https://partner-api.sihot.com/PDOCS/API/CBS/SihotServices01?wsdl' using WS-Metadata Exchange and HttpGet.
Generating files...
C:\src\dotnet\GettingStarted360Net6\ServiceReference\Reference.cs

Note for the purpose of demonstration we also generate the synchronous methods for using the services, this is not required but makes the tutorial easier to follow.

Once finished run the following command to load all dependencies.

C:\src\dotnet\GettingStarted360Net6>dotnet restore
  Wiederherzustellende Projekte werden ermittelt...
  "C:\src\dotnet\GettingStarted360Net6\GettingStarted360Net6.csproj" wiederhergestellt (in "3,01 sec").

Important Note: At the time of this writing the svcutil has an issue to generate Service References more details can be found here. From the link we use the following code inside our program to work around the issue.

MethodInfo method = typeof(XmlSerializer).GetMethod("set_Mode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
method.Invoke(null, new object[] { 1 }); 

Once this is done we can initialize the client to use the service

SihotServices01PortTypeClient client = new SihotServices01PortTypeClient(SihotServices01PortTypeClient.EndpointConfiguration.SihotServices01Port, Environment.GetEnvironmentVariable("WSURL") );

Step 3 – Authentication / Requesting a securityID (token)

To authenticate and receiving a securityID the authenticate request is required. See also Authentication for more information.

The structure of the AuthenticateRequest can be reviewed seen Authenticate

String getSecurityID()
{
    if ( securityID.Length > 0 &&  tokenValidUntil < DateTime.Now.AddSeconds(20) )
    {
        return securityID;
    }

    AuthenticateRequest request = new AuthenticateRequest();
    request.AuthenticationInfos = new AuthenticateRequestAuthenticationInfos()
    {
        user = Environment.GetEnvironmentVariable("SIHOT_USER"),
        password = Environment.GetEnvironmentVariable("SIHOT_PASSWORD"),
        hotel = Environment.GetEnvironmentVariable("SIHOT_HOTEL")
    };

    try
    {
        var response = client.Authenticate(request);
        Console.Write("securityID received: ");
        Console.WriteLine(response.Authentication[0].SecurityID);

        securityID = response.Authentication[0].SecurityID;
        tokenValidUntil = DateTime.Now.AddSeconds(Int32.Parse(response.Authentication[0].DurationInSec));

        return securityID;
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        return "";
    }
}

In this step we will write a new function that will call the api to retrieve the in-house guests for a certain day.

S_GUEST_IN_HOUSE_SEARCH_V001Response getGuestInHouseGuests(String callingDate)
{
    var req = new S_GUEST_IN_HOUSE_SEARCH_V001Request()
    {
        Authentication = new Authentication()
        {
            SecurityID = securityID
        },
        GuestInHouseSearch = new S_GUEST_IN_HOUSE_SEARCH_V001RequestGuestInHouseSearch()
        {
            date = callingDate
        }
    };

    var res = client.S_GUEST_IN_HOUSE_SEARCH_V001(req);

    if  (! res.Result.Success.Equals("true") )
    {
        Console.WriteLine("Something is not right");
        return res;
    }

    showInhouseGuests(res);
    return res;
}

Step 5 – Showing the result

void showInhouseGuests(S_GUEST_IN_HOUSE_SEARCH_V001Response res)
{
    foreach ( S_GUEST_IN_HOUSE_SEARCH_V001ResponseRoom r in res.room )
    {
        Console.Write( "Room type: " + r.category +  ": ");
        foreach( S_GUEST_IN_HOUSE_SEARCH_V001ResponseRoomPerson p in r.Person )
        {
            Console.WriteLine(p.name1 + ", " + p.name2);
        }
    }
}

Step 6 – Bringing all together

static void Main(string[] args)
{
    MethodInfo method = typeof(XmlSerializer).GetMethod("set_Mode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
    method.Invoke(null, new object[] { 1 });

    Console.WriteLine("Starting up");

    var p = new Program();
    var until = p.getSecurityID();
    Console.WriteLine(until);

    Console.WriteLine(p.tokenValidUntil);
    Console.WriteLine("Searching in-house guests for " + DateTime.Now.ToString("yyyy-MM-dd"));
    p.getGuestInHouseGuests(DateTime.Now.ToString("yyyy-MM-dd"));

    Console.WriteLine("Finish");
}

To compile and run simply run gradlew run. The output show similar like this:

> dotnet run
Starting up
securityID received: 250LX4Wm8Dw6EpnvPAKknG59bsRz9HZ2Z8OAZQ0Qr8jLTR2d9oAtVPwz7wWbGRClUtAF3STauFrSLvRn7f7FfYh72eKpX3Lt9KdNAo+5XFzw2Cj7Ppx+EkWxNwSVQExUtw==
250LX4Wm8Dw6EpnvPAKknG59bsRz9HZ2Z8OAZQ0Qr8jLTR2d9oAtVPwz7wWbGRClUtAF3STauFrSLvRn7f7FfYh72eKpX3Lt9KdNAo+5XFzw2Cj7Ppx+EkWxNwSVQExUtw==
24.12.2021 13:38:55
Searching in-house guests for 2021-12-24
Room type: BD: Franz, Peter
Finish

What is next?

Download of the Source

A complete working example can be downloaded at: - GettingStarted_Net6.zip

To install the project run:

dotnet restore

Please ensure that you enter username, password and hotel ot the setEnvironment.bat configuration file!

run the example project

dotnet run