Creating a Web Service Server using the SGI specification

From HTNG Connectivity Wiki

Jump to: navigation, search

Using Visual Studio to create the Web Service

We start this by opening Visual Studio and selecting an "ASP.NET Web Service Application". Note that in this example I will be storing my files in a directory called App_Code which is alongside of my WSDL and Schema. This is good practice as it keeps my source files separate from the code you would be likely to move into production and maintains consistency with Visual Studio 2005


The resulting template application really starts off as a shell. This is where we need to do a few things

    • Change the Web Service namespace to
    • Remove the Hello World example (that is already generated in the file)
    • Add a the ServiceInterfaces.cs generated code
    • Add a reference to the HTNG.PWS.SGI namespace (defined in ServiceInterfaces.cs)
    • Add references to the Interfaces within ServicesInterfaces.cs and Implicity generate the code to support these interfaces

We'll start off with item number (3) from above. Visual Studio provides a simple way to add the ServiceInterfaces.cs code to the project. Right click on the project within the Solution explorer within the right hand panel and use the "Add -> Existing Item" feature. Here is a step by step walk through of this process:


Within the file selection dialogue menu, choose the ServiceInterfaces.cs file:


After adding the reference to the ServiceInterfaces namespace via the using HTNG.PWS.SGI; each of the Interfaces need to be added to our web service. In the case of the Single Guest Itinerary there are a number of bindings that house the various web service operations. These are best understood by looking at the WSDL:


As you can see from the WSDL we will need to implement the following:-

    • IActivityBinding
    • IActivityProviderBinding
    • IActivitySyncBinding
    • INameBinding
    • IReservationProviderBinding
    • IReservationSyncBinding

Each of these will be described as an interface within the ServiceInterfaces.cs source when the "wsdl" utility was run. These are added to the service as follows:


Visual Studio provides a neat feature that helps to generate the code needed implicity to operate with each interface. Notice in the screen above the small horizontal line underneath the "I" if you mouse over these Visual Studio will provide some options to implicity or explicitly create the needed classes. You can also create these by use a right mouse click over each interface and choosing "Implement Interface"


Selecting the drop down allows you to implement the interface


The finished product has all of the interfaces implemented in code.


Congratulations !! .. You can then run the web service and Visual Studio will implement it on the fly within it's development web server "Cassini" to produce your web service.


Along with the ServiceInterfaces.cs interface definitions file generated the end result of this process are a number of key files that will be part of your Visual Studio solution.

  • AssemblyInfo.cs (Usually in the Properties directory)
  • Global.asax
  • Global.asax.cs
  • Service1.asmx
  • Service1.asmx.cs
  • Web.config

AssemblyInfo File

An assembly is the functional unit for sharing and reuse in the common language runtime. For more information about assemblies and configuration you may need to perform some research on read some documentation on "Understanding the .NET Framework". The AssemblyInfo file consists of general information about the assemblies in the project. To modify the assembly information, such as the version number, you change the attributes in the AssemblyInfo file.

Web.config File

This file contains configuration information, such as the debug mode and the authentication mode for a Web project. It also includes information about whether to display custom errors for a Web project. You can also use the Web.config file to store custom configuration information for your XML Web service.

Global.asax and Global.asax.cs Files

These files enable you to manage application-level and session-level events. These files reside in the root directory of an ASP.NET Web application or ASP.NET Web service. The Global.asax.cs class file is a hidden, dependent file of Global.asax, which contains the code for handling application events such as the Application_OnError event.

Service1.asmx and the Service1.asmx.cs Files

These two files make up a single XML Web service. The Service1.asmx file contains the XML Web service processing directive and serves as the addressable entry point for the XML Web service. The Service1.asmx.cs class file is a hidden, dependent file of WebService.asmx and contains the code-behind class for the XML Web service.

The next section Migrating the Web Service to IIS provides details on how to move this code into IIS so we can communicate with it.

Personal tools
administrative tools