What s a Web Service?

What’s a Web Service?

To break complex programs into manageable tasks, programmers make extensive use of functions. Each function within a program should perform specific processing (a service). For example, the following C program, Hello.c, uses the printf function to display a message to the user:

#include <stdio.h> void main(void)   {     printf("Hello, Programming World");   }

In a similar way, the following Visual Basic .NET code fragment, from the program DisplayDateTime.vb, uses the Now and MessageBox.Show functions to retrieve and then display the current date and time and the Close function to close the current form:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As _ Ä   System.EventArgs) Handles MyBase.Load    MessageBox.Show("Current Date and time is: " & Now(), _       "Display Date & Time")    Me.Close() End Sub

Think of a web service as a function your programs can use to accomplish specific tasks. Just as a function can receive (and possibly change) parameter values, so too can a web service. Likewise, just as functions often return a value to the calling program, so too can a web service.

To use a function such as printf or MessageBox.Show, you must know the type of value the function returns as well as the number and types of parameters you can pass to the function. The same is true for a web service.

What makes a web service different from a traditional function is that the code for the web service resides on a remote server. Before a program can use a web service, the PC running the program must have a network connection (a dial-up connection will suffice).

When your program calls a web service (using a function call), your program, as shown in Figure 1.1, will send a network message to the server that specifies the desired service. If the web service requires parameters, the message will include values for each.

click to expand
Figure 1.1: To call a web service, a program sends a network message to the server upon which the web service resides.

After the server completes the web service’s processing, the server, as shown in Figure 1.2, will send a network message containing the service’s result back to your program.

click to expand
Figure 1.2: After the server executes the web service's instructions, the server will send a network message containing the service's result to the calling program.

Because a web service requires the exchange of network messages and because the server that executes the service may be busy performing other tasks, a web service will execute substantially slower than a standard function. Depending on factors such as network traffic, the amount of time a web service will require may vary from one use of the service to the next.

. NET Web Services Solutions
.NET Web Services Solutions
ISBN: 0782141722
EAN: 2147483647
Year: 2005
Pages: 161
Authors: Kris Jamsa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net