Getting a Feel for Web Service Overhead

As discussed, many operations, because of network overhead, are not well suited for implementation as a web service. The following C# program, MeasureOverhead.cs, creates functions that call the functions that swap values of type string, double, and integer. The program

calls the functions to swap 100 values of each type. Then, the program uses the Swap web service methods to perform identical processing. The program then displays the amount of time the standard functions required as well as the amount of time required by the web service methods, as shown in Figure 2.9.


Figure 2.9: Measuring the overhead (in milliseconds) of web service operations

If you compare the number of clock ticks (milliseconds) the local functions required to that required by the web service methods, you should gain an appreciation for the amount of overhead a program will incur by calling a web service.

To create the MeasureOverhead.cs program, perform these steps:

  1. Within Visual Studio .NET, select the File menu New Project option. Visual Studio .NET will display the New Project dialog box.

  2. Within the New Project dialog box Project Types list, click C# Projects. Then, within the Templates field, click Windows Application. Within the Name and Location fields type MeasureOverhead. Select OK. Visual Studio .NET will display a form onto which you can drag and drop the program’s controls (label, buttons, and text box).

  3. Using the Toolbox, drag and drop buttons and text boxes previously shown in Figure 2.9 onto the page.

  4. Select the Project menu Add Web Reference option. Visual Studio .NET will display the Add Web Reference dialog box.

  5. Within the Address field, type localhost/Swap/Service1.asmx?WSDL and press Enter. The dialog box will load the file’s contents. Click the Add Reference button.

  6. Select the View menu Code option. Visual Studio .NET will display the program’s source code. Within the source code add the following program statements:

          private void LocalSwapInteger(ref int a, ref int b)       {          int temp;          temp = a;          a = b;          b = temp;          }       private void LocalSwapDouble(ref double a, ref double b)       {          double temp;          temp = a;          a = b;          b = temp;       }       private void LocalSwapString(ref string a, ref string b)       {          string temp;          temp = a;          a = b;          b = temp;       }       private void button2_Click(object sender, System.EventArgs e)       {          localhost.Service1 SwapObject = new localhost.Service1();          string F = "AAAA";          string G = "BBBB";          double C = 1.987654321;          double D = 9.123456789;          int A = 0;          int B = 1001;          long start_ticks, end_ticks, processing_time;          start_ticks = DateTime.Now.Ticks;          for (int i = 0; i < 100; i++)          {              try             {                SwapObject.SwapInteger(ref A, ref B);                SwapObject.SwapDouble(ref C, ref D);                SwapObject.SwapString(ref F, ref G);             }             catch (Exception Ex)             {                MessageBox.Show(Ex.Message);             }          }          end_ticks = DateTime.Now.Ticks;          processing_time = end_ticks - start_ticks;          textBox2.Text = "Ticks: " + processing_time.ToString();       }       private void button1_Click(object sender, System.EventArgs e)       {          string F = "AAAA";          string G = "BBBB";          double C = 1.987654321;          double D = 9.123456789;          int A = 0;          int B = 1001;          long start_ticks, end_ticks, processing_time;          start_ticks = DateTime.Now.Ticks;          for (int i = 0; i < 100; i++)          {                LocalSwapInteger(ref A, ref B);                LocalSwapDouble(ref C, ref D);                LocalSwapString(ref F, ref G);          }          end_ticks = DateTime.Now.Ticks;          processing_time = end_ticks - start_ticks;          textBox1.Text = "Ticks: " + processing_time.ToString();       }

When the user clicks the Swap Local button, the program code will call the local functions within a for loop to exchange the values 100 times. Because the functions reside in RAM, the program can complete its processing very quickly. When the user clicks the Swap web button, the program will use the Swap web service methods within a for loop to exchange the values 100 times. The network overhead of the web service calls causes the operations to execute much slower. The program displays the number of clock ticks each swap operation required within the text boxes.




. 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