Example: Basic Call for SOAP Services

Adding web references can be done in Visual Studio. This generates a proxy class that consumes the TecRMI SOAP service and the related object model automatically. Required assembly references will also be automatically added.

  • Go to the project explorer and rightclick on references of the project where you want to add the web reference.
  • In the context menu click "Add Service Reference...".
  • In the opened dialog click "Advanced...".
  • In the opened dialog click "Add Web Reference...".
  • Type the service address "https://rmi-services.tecalliance.net/soap/ServiceCommon.asmx" in the "URL" field.
  • Click the "Go" button and wait until the service is found.
  • Type "Services.TecRMI.Common" as namespace of the service proxy class in the "Web Reference Name" field.
  • Click "Add Reference".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Web.Services.Protocols;
using Examples.CSharp.Soap.Services.TecRMI.Common;
 
namespace Examples.CSharp.Soap
{
    /// <summary>   A SOAP example. </summary>
    public static partial class SoapExample
    {
        /// <summary>   Example of basic call. </summary>
        /// <remarks>
        /// Shows how to call the service by submitting a simple data structure as parameters.
        /// </remarks>
        /// <param name="company">  The company name. </param>
        /// <param name="account">  The user name. </param>
        /// <param name="password"> The password. </param>
        public static void BasicCall(string company, string account, string password)
        {
            // Create the message object using the auto-generated types.
            var msg = new GetLanguagesMsg
            {
                // Credentials
                CompanyName = company,
                UserName = account,
                Password = password,
 
                // Method specific parameters
                LanguageCode = "en",
            };
 
            // response type
            Language[] languages;
 
            using (var serviceCommon = new ServiceCommon { Url = "https://rmi-services.tecalliance.net/soap/ServiceCommon.asmx" })
            {
                try
                {
                    // Call the service using the auto-generated proxy.
                    languages = serviceCommon.GetLanguages(msg);
                }
                catch (SoapException ex)
                {
                    // SOAP exception occurs if errors on TecRMI side occur, see message (e.g. "Permission denied")
                    Console.WriteLine("SOAP Error: {0}", ex.Message);
                    serviceCommon.Abort();
                    return;
                }
                catch (Exception ex)
                {
                    // other exception (e.g. timeout)
                    Console.WriteLine("other Error: {0}", ex.Message);
                    serviceCommon.Abort();
                    return;
                }
            }
 
            // Process the response
            Console.WriteLine(" Id | Code | Name");
            Console.WriteLine("----+------+------------");
            foreach (var lang in languages)
            {
                Console.WriteLine(
                    " {0,2} | {1,-4} | {2}",
                    lang.LanguageId,
                    lang.LanguageCode,
                    lang.LanguageName);
            }
        }
    }
}
 
©   TecAlliance GmbH