get consultation

What are Web Services?

Introduction to Web Services

What are Web Services?

Web Services allows the transfer of XML between different systems. Web Services do not care what kind of operating system you are using. It does not care what kind of file format your have. It does not care what computer programming language you are using. It uses XML to transfer data between servers and clients.

Everything on the web provides a service. Amazon.com provides a service for selling books and such. FedEx.com provides a service for tracking packages. Google.com provides a service for searching the web for information.

A web service does not need to know anything about the system your clients use. You can build a web service in any .NET language and have it be used in any language that knows XML.

It is a way to distribute the workload of your application. In the past, developers would write their programs as modules. Those modules would have certain services. Now instead of having those modules on the same machine, those modules are now written onto the web and distributed on the web. Web Services allows you to increase interoperability.

The basic tenets of Web Services are:

  • Allow pieces of software written in various languages to communicate with each other regardless of the operating system.
  • It uses the XML standard to communicate between the systems. Integration between old and new systems is very easy.
  • Applications running in different organizations can be hooked up to each other very easily. This is still a lot of work, but easy to do.

Terminology

UDDI - Directory of Services - Describes what services are available . Lists of vendors that provide services, such as uddi.org. This is the Yahoo of Web Services. It provides a catalog of Web Service vendors and their services. This mechanism allows providers to advertise the existence of their Web services and for Web service consumers to locate Web services of interest. See XML Web Service Directories for more details.

DISCO - Service Discovery - Describe how to find the service . The DISCO file is created and given to clients so that they can find your service. This is an XML-based file that contains links (URLs) to the XML Web Service. See XML Web Service Discovery for more details.

WSDL - Service Description - Describes the service. It is an XML-based file for describing a Web service. WSDL stands for Web Services Description Language. It is a service agreement between the server and the client. It details what methods are available, how to call them, and what results to expect. See XML Web Service Description and W3C for more details.

SOAP - Service Communication - Describes the how to communicate with the service. SOAP is used when communicating between the service and the client. This communication happens via the HTTP port, so it uses Internet standard communication. See XML Web Service Wire Formats or W3C for more details.

XSD - Universal Type System - Describes the types used by the functions. XSD stands for XML Schemas and Data. The XSD is a set of rules that define the structure and content of the XML data. This is important because when we call a web service function we need to know how to call the function and how to process the results. This is defined in XSD. See XML Schema Reference (XSD) for more details.

XML - Universal Data Format - Describes the format used to pass information between the client and service. XML is the format used to pass data between the two systems. This is similiar to how HTML is a format used to pass information between a website and a browser. See Introduction to XML for more details.

A Sample Web Service

Marking a function as a callable via the web is simply a matter of using the WebMethod attribute. Using Visual Studio .NET, you simply create a Web Service project and then tag the function with the WebMethod attribute. This makes the function visible as a Web Service method.

If the client were to inspect this service, they would see the SubmitOrder as method that is callable. We'll see later how a client would be able to inspect this service.

[WebMethod]
public void SubmitOrder(PO po)
{
    // Process the order...
}

public class PO
{
    public string shipto;
    public string bill;
    public string comment;
    public ITEM[] items;
    public DateTime orderdate;
}

public struct ITEM
{
    int partno;
    string desc;
}

If a client were to submit an order using this Web Service method, the client would use the following XML file to pass the information from the client to the Web Service.

Here we are using the SOAP (Simple Object Access Protocol) Protocol specification. The Envelope is mandantory and contains the contents of the message. The Envelope contains a Body which contains the call (SubmitOrder) information. 

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitOrder xmlns="http://tempuri.org/">
      <po>
        <shipto>Bellevue, WA</shipto>
        <bill>Dan Vallejo</bill>
        <comment>>Early Christmas gifts</comment>
        <items>
          <ITEM />
          <ITEM />
        </items>
        <orderdate>12/31/2002</orderdate>
      </po>
    </SubmitOrder>
  </soap:Body>
</soap:Envelope>

The Web Service would then parse this XML data back into native data (PO and ITEM types) and then process the information.

Available Web Services

The Google Web APIs allow you perform a query on the web. It allows your web site to use the same search engine that Google uses. Later, we will look at this Web Service in more detail.

XMethods provides a whole directory of Web Service providers in an easy to use fashion.

eYesoft provides a small list of Web Service providers.

WebserviceX.NET has a small list as well.

Demo

Let's write a web service to verifies user names and password.

  1. From the main menu select File | New | Project

  2. Select Visual C# Projects and ASP.NET Web Service.

  3. Press OK.

  4. Click on "click here to switch to code view."

  5. Uncomment the HelloWorld function.

  6. Add the following function to validate users and passwords:

    [WebMethod]
    public bool ValidatePassword(string userName, string password)
    {
        if (userName == "dan" && password == "pass")
            return true;
        else
            return false;
    }

  7. Press F5. You'll see two operations that this web service can perform.

  8. Click on HelloWorld and press Invoke. You'll see a browser pop up with the Hello World XML string. Close the XML browser window.

  9. Click on ValidatePassword. Notice that you have a couple of text boxes. This is because your function requires two string parameters.

  10. Enter an invalid name and password and notice that the XML indicates false.

  11. Enter dan and pass and notice that the XML indicates true.

Obviously, you wouldn't hard-code the valid names and passwords. Most likely, you'd have a database of some sort or a text file and validate it against it.

Web services are not designed to work in this fashion. They are typically used in programs. For example, I have a Windows application and I want the user to be able to enter a FedEx tracking number. The program would call the FedEx web service and display the information in the Windows application. We'll see this in the next demo.