Web Services

Last Updated: 2001

The difference between DISCO and UDDI is that to use DISCO you need the know the URL of the server supporting the desired service. To use UDDI you need to know the location of the URL "Yellow Pages" book and have a description of the desired service you require.

In theory, the sequence goes something like this:

  1. You need a particularly service, say the verification of a VISA number.

  2. You use UDDI to get a DISCO or WSDL document for a suitable service from a "Yellow Pages" site - perhaps uses additional criteria such as cost to narrow the field.

  3. You if have a DISCO you use that to identify the server to request the WSDL document for the service.

  4. Using the information contained in the WSDL you invoke the right service using the described protocols and parameters, and get the result in the described format..

In practice, unless the system is dynamic, steps 1 to 3 only occurs during design time

.

Web Services & .NET

 

Writing Web Services

  1. Create a asmx/asmx.cs file set. A single .asmx file set can hold define services.

  2. For each service create a new public class derived from System.Web.Services.WebService

  3. For each operation the service supports, add a public method with an attribute of WebMethod

    Example:

    using System;
    using
    System.Web;
    using
    System.Web.Services;
    namespace
    WebService2 {
       
    public class Service1 : System.Web.Services.WebService {
            [WebMethod]
           
    public int Add(int a, int b) {
               
    return a+b;
            }

            [WebMethod(MessageName="Add3")]
           
    public int Add(int a, int b, int c) {
               
    return a+b+c;
            }

            [WebMethod]
           
    public void AddByRef(int a, int b, ref int c) {
                c=a+b;
            }

            [WebMethod]
           
    public int AddClass(myClass a, myClass b) {
               
    return a.iNum + b.iNum;
            }
        }
       
       
    public class myClass {
           
    public int iNum;
        }
    }

    Notes:

    1. If its serialisable, it can be used as a parameter. Note the ref parameter in the AddByRef operation and the classes in the AddClass operation.

    2. If you write the code through the VS interface additional code will be generated to support the designer. This allows the "dropping" or other components onto the web service.

    3. Everything available to a normal web application is available here, such as Application["SomeRef"] caching. I wouldn't try UI if I were you though.

    4. Web Services do not, by default, support session state. To enable session state (and thus be able to use things like the Session object) the EnableState attribute needs to be specified in the WebMethod attribute, i.e. [WebMethod(EnableSession=true)]. The application object is not a session object, so is available irrespective of this setting.

Calling Web Services

  1. To get a user-friendly interpretation of the WSDL file look at the service through  a browser, e.g. http://localhost/WebService2/Service1.asmx (This can be turned off)
     

  2. Through HTTP GET,e.g.  http://localhost/WebService2/Service1.asmx/Add?a=2&b=2 (if a parameter is an object, HTTP GET cannot be used)
     

  3. Through SOAP. Add a Web Reference to the calling project, then create an object of the right type and call the operation on it:

        localhost.Service1 oS1 = new localhost.Service1();
        oS1.Add(1,2);

Note:

  1. No Using statement is required.

  2. "localhost" is a proxy object so named because that was part of the URL to the disco file. We could easily have created it with a different name and their are command line tools to create the proxy automatically if you want to do it on the fly (or outside of the VS IDE). The proxy object can support multiple services (don't know if those services can reside on different servers though).
     

Calling a web-service from DHTML

 

SOAP