Consuming webservices with gprs

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Krudler (bdw4_at_waikato.ac.nz)
Date: 02/12/05


Date: Sun, 13 Feb 2005 10:04:40 +1300

have a simple application that tries to consume a web service. It works
fine when the PocketPC is connected to the Internet via ActiveSync, but when
it attempts to use a GPRS connection, only the first invocation of the web
service succeeds, all others fail with a WebException. - protocolerror

If I close the application and restart it will allow me to access the
webservice again but only once,
I thought it may have had something to do with the garbage collector , but
adding cleanup code doesnt seem to help

If have installed .NETCF Service Pack 3 onto my devices but the problem
still exists.
I am testing on smartphone 2003 and ppc 2003

I have found that calling the webservice using http post works for muliple
webrequest

Here is some sample test code,

It works fine over gprs if I use my httprequesttest method muliple times, if
I use the my webserviceproxytest it only works once over gprs.
They both work fine if connected through acticesync.

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Xml;
using System.IO;
using System.Text;

namespace Smartphonetester
{
 /// <summary>
 /// Summary description for Form1.
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.MainMenu mainMenu2;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.CheckBox checkBox1;
  private System.Windows.Forms.MainMenu mainMenu1;
  private ConfigServices.DeviceManagement deviceManagement;
  private System.Windows.Forms.TextBox textBox1;
  private int count = 0 ;

  public Form1()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }
  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   base.Dispose( disposing );
  }
  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.mainMenu2 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.checkBox1 = new System.Windows.Forms.CheckBox();
   this.textBox1 = new System.Windows.Forms.TextBox();
   //
   // mainMenu2
   //
   this.mainMenu2.MenuItems.Add(this.menuItem1);
   //
   // menuItem1
   //
   this.menuItem1.Text = "Exit";
   this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
   //
   // checkBox1
   //
   this.checkBox1.Location = new System.Drawing.Point(16, 128);
   this.checkBox1.Text = "checkBox1";
   this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click);
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(8, 16);
   this.textBox1.Multiline = true;
   this.textBox1.Size = new System.Drawing.Size(152, 96);
   this.textBox1.Text = "textBox1";
   //
   // Form1
   //
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.checkBox1);
   this.Menu = this.mainMenu2;
   this.Text = "Form1";

  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>

  static void Main()
  {

   Application.Run(new Form1());

  }

  private void menuItem1_Click(object sender, System.EventArgs e)
  {
   Application.Exit();
  }

  private void checkBox1_Click(object sender, System.EventArgs e)
  {
   webserviceproxytest();
  }

  private void webserviceproxytest()
  {

   deviceManagement = new ConfigService.DeviceManagement();
   deviceManagement.Url = "mywebserviceURL";

   deviceManagement.Timeout = 100000;//The default is 100 000 milliseconds.

   int userid = Int32.MinValue;

   FlowGroup.Crypto.MD5 md =
FlowGroup.Crypto.MD5CryptoServiceProvider.Create();
   byte[] hash;
   System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
   byte[] buffer = enc.GetBytes("password");
   hash = md.ComputeHash(buffer);

   try
   {

    ConfigurationServices.ReturnCode rc = deviceManagement.AuthUser("brad",
hash, out userid);
    textBox1.Text = userid.ToString();
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.Message);
   }

   deviceManagement.Abort();

  }

  private void httprequesttest()
  {

   // Create a 'WebRequest' object with the specified url.
   WebRequest myWebRequest = WebRequest.Create("mywebserviceURL+params");

   // Send the 'WebRequest' and wait for response.
   WebResponse myWebResponse = myWebRequest.GetResponse();

   // Obtain a 'Stream' object associated with the response object.
   Stream ReceiveStream = myWebResponse.GetResponseStream();

   Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

   // Pipe the stream to a higher level stream reader with the required
encoding format.
   StreamReader readStream = new StreamReader( ReceiveStream, encode );
   StringBuilder output = new StringBuilder();

   output.Append("\nResponse stream received");
   Char[] read = new Char[256];

   // Read 256 charcters at a time.
   int count = readStream.Read( read, 0, 256 );
   output.Append("HTML...\r\n");

   while (count > 0)
   {
    // Dump the 256 characters on a string and display the string onto the
console.
    String str = new String(read, 0, count);
    output.Append(str);
    count = readStream.Read(read, 0, 256);
   }

   textBox1.Text = output.ToString();

   // Release the resources of stream object.
   readStream.Close();

   // Release the resources of response object.
   myWebRequest.Abort();
   myWebResponse.Close();

  }

 }
}

Thanks
Brad



Relevant Pages

  • Re: Threads on an Intermec 751 plist
    ... We use a thread to process cached web service calls in the background ... private void DisconnectedProcessor() ... bool bSuccess = true; ... exceptionCode = soapEx.GetBaseException.Message; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Asynchronous web service calls
    ... Some of the web method calls are probably failing - my guess is its the "The ... request failed with HTTP status 403" exception (i.e., ... private void btnRun_Click ... > I have a web service with 1 method: ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Threads on an Intermec 751 plist
    ... We use a thread to process cached web service calls in the background ... private void DisconnectedProcessor() ... exceptionCode = soapEx.GetBaseException.Message; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Problem with Exception Handling using Web Services
    ... private void checkPassword ... The Exception is definitely thrown, but when I run it in a web browser it ... >> Microsoft Visual C#.NET to interact with the web service. ... >> Adrian Burka ...
    (microsoft.public.dotnet.framework.webservices)
  • Help!! Creating a RAS _VPN Network connection class - Problem
    ... I like to create a Remote ... remote server as verified if internet connection is ok. ... private void StartWatch() ...
    (microsoft.public.dotnet.framework)