ProtocolError - WebServices

N

nzpcmad

The device I am developing on uses CE 4.10. It's current Compact
Framework version is the SP2 upgrade.

I use Visual Studio 2003 and C# for development.

It connects via GPRS.

I wrote a simple app. to demonstrate this problem. It is a version of
the Microsoft MathsClient.

The first time it works fine - from then on it throws ProtocolError.

But it works perfectly from the emulator.

Any ideas?

Thank you

The WSDL is here:

http://samples.gotdotnet.com/quicks...services/MathService/CS/MathService.asmx?WSDL

---------------------------------------------
Source code follows:

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.IO;
//using MathServiceCS.com.gotdotnet.samples;
using MathsClient.com.gotdotnet.samples;

namespace MathClientCS
{
/// <summary>
/// Summary description for MathClient.
/// </summary>
public class MathClient : System.Windows.Forms.Form
{
//MathService myMath = new MathService();

private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnSub;
private System.Windows.Forms.Button btnMul;
private System.Windows.Forms.Button btnDivide;
private System.Windows.Forms.Label lblOp1;
private System.Windows.Forms.TextBox txtOp1;
private System.Windows.Forms.TextBox txtOp2;
private System.Windows.Forms.Label lblOp2;
private System.Windows.Forms.Label lblResult;
//private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;

float operand1;
float operand2;

MathService myMath;

private enum Operation
{
ADD,
SUBTRACT,
MULTIPLY,
DIVIDE
}

private Operation currentOperation;

public static bool WRITE_TO_SOAP_LOG = true;

public MathClient()
{
//
// Required for Windows Form Designer support
//

InitializeComponent();
myMath = new MathService();

//
// 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.btnAdd = new System.Windows.Forms.Button();
this.btnSub = new System.Windows.Forms.Button();
this.btnMul = new System.Windows.Forms.Button();
this.btnDivide = new System.Windows.Forms.Button();
this.lblOp1 = new System.Windows.Forms.Label();
this.txtOp1 = new System.Windows.Forms.TextBox();
this.txtOp2 = new System.Windows.Forms.TextBox();
this.lblOp2 = new System.Windows.Forms.Label();
this.lblResult = new System.Windows.Forms.Label();
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(152, 40);
this.btnAdd.Text = "Add";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnSub
//
this.btnSub.Location = new System.Drawing.Point(152, 72);
this.btnSub.Text = "Subtract";
this.btnSub.Click += new System.EventHandler(this.btnSub_Click);
//
// btnMul
//
this.btnMul.Location = new System.Drawing.Point(152, 104);
this.btnMul.Text = "Multiply";
this.btnMul.Click += new System.EventHandler(this.btnMul_Click);
//
// btnDivide
//
this.btnDivide.Location = new System.Drawing.Point(152, 136);
this.btnDivide.Text = "Divide";
this.btnDivide.Click += new
System.EventHandler(this.btnDivide_Click);
//
// lblOp1
//
this.lblOp1.Location = new System.Drawing.Point(8, 40);
this.lblOp1.Size = new System.Drawing.Size(72, 20);
this.lblOp1.Text = "Operand 1:";
//
// txtOp1
//
this.txtOp1.Location = new System.Drawing.Point(80, 40);
this.txtOp1.Size = new System.Drawing.Size(64, 20);
this.txtOp1.Text = "4";
//
// txtOp2
//
this.txtOp2.Location = new System.Drawing.Point(80, 72);
this.txtOp2.Size = new System.Drawing.Size(64, 20);
this.txtOp2.Text = "2";
//
// lblOp2
//
this.lblOp2.Location = new System.Drawing.Point(8, 72);
this.lblOp2.Size = new System.Drawing.Size(72, 20);
this.lblOp2.Text = "Operand 2:";
//
// lblResult
//
this.lblResult.Location = new System.Drawing.Point(16, 112);
this.lblResult.Size = new System.Drawing.Size(120, 24);
//
// MathClient
//
this.ClientSize = new System.Drawing.Size(234, 268);
this.Controls.Add(this.lblResult);
this.Controls.Add(this.lblOp2);
this.Controls.Add(this.txtOp2);
this.Controls.Add(this.txtOp1);
this.Controls.Add(this.lblOp1);
this.Controls.Add(this.btnDivide);
this.Controls.Add(this.btnMul);
this.Controls.Add(this.btnSub);
this.Controls.Add(this.btnAdd);
this.Text = "Simple Math Service";

}
#endregion

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

static void Main()
{
Application.Run(new MathClient());
}

private void btnAdd_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
lblResult.Text = "";
operand1 = float.Parse(txtOp1.Text);
operand2 = float.Parse(txtOp2.Text);
currentOperation = Operation.ADD;
lblResult.Text = "Add result = " + invoke (currentOperation,
operand1, operand2);
Cursor.Current = Cursors.Default;
}

private void btnSub_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
lblResult.Text = "";
operand1 = float.Parse(txtOp1.Text);
operand2 = float.Parse(txtOp2.Text);
currentOperation = Operation.SUBTRACT;
lblResult.Text = "Sub result = " + invoke (currentOperation,
operand1, operand2);
Cursor.Current = Cursors.Default;
}

private void btnMul_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
lblResult.Text = "";
operand1 = float.Parse(txtOp1.Text);
operand2 = float.Parse(txtOp2.Text);
currentOperation = Operation.MULTIPLY;
lblResult.Text = "Mul result = " + invoke (currentOperation,
operand1, operand2);
Cursor.Current = Cursors.Default;
}

private void btnDivide_Click(object sender, System.EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
lblResult.Text = "";
operand1 = float.Parse(txtOp1.Text);
operand2 = float.Parse(txtOp2.Text);
currentOperation = Operation.DIVIDE;
lblResult.Text = "Div result = " + invoke (currentOperation,
operand1, operand2);
Cursor.Current = Cursors.Default;
}

private string invoke (Operation mathOp, float operand1, float
operand2)
{
try
{
switch (mathOp)
{
case Operation.ADD:
return myMath.Add(operand1, operand2).ToString();
case Operation.SUBTRACT:
return myMath.Subtract(operand1, operand2).ToString();
case Operation.MULTIPLY:
return myMath.Multiply(operand1, operand2).ToString();
case Operation.DIVIDE:
return myMath.Divide(operand1, operand2).ToString();
}
}

catch (WebException we)
{
MessageBox.Show ("Web Error " + we.Status + " " + we.Response + "
" + we.Message);

if (we.Status == System.Net.WebExceptionStatus.ProtocolError)
{
System.Net.WebResponse response = we.Response;
if (response != null)
{
System.IO.StreamReader sr = new
StreamReader(response.GetResponseStream());
string s = sr.ReadToEnd();
MessageBox.Show (s);
}
}
}

catch (Exception ex)
{
MessageBox.Show ("Error " + ex.Message);
}

return "Error";
}


}
}
 
G

Guest

Is the web service running on your machine?
Are you connecting to the web service via ActiveSync?

I've had similar problems when trying to debug my application. I ever have to wait for a while before connecting again our turn off "HTTP Keep-Alives Enabled" in IIS. Problem with the second solution is that you can't debug the web service.

Chris.
 
N

nzpcmad

Chris,

Your question confuses me?

The device is using GPRS to connect to the Internet. It does not use
my PC to connect in any way.

I can connect the device to my PC via ActiveSynch but that's not how
the device accesses the Internet.

I'm not trying to debug the application on the CE.NET device - I am
trying to run it.

Thanks
 
G

Guest

Sorry if I confused you, I was just trying to put some suggestions forward that may help.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top