.Net CF Web Service

¶©¼z

Is it possible to use .Net Compact Framework to consume web services that
implemented cookieless session? I've surfed the web to find out the solution
for a few weeks. I can only get some examples that consume sessionless web
service.

Can anyone give me some sample code or references?

Thank you very much!
 
D

Dino Chiesa [Microsoft]

Have you examined this article?
http://msdn.microsoft.com/library/en-us/dnservice/html/service08062002.asp

This technique worked for me on the .NET CF, as well as on the desktop .NET
Framework.

EG, here's the code that worked on my pocketpc:

private Uri webServiceUrl;
private void button1_Click(object sender, System.EventArgs e) {
int x;
// Set the Url on the proxy
if (webServiceUrl == null)
webServiceUrl = new Uri(svc1.Url);
else
svc1.Url = webServiceUrl.AbsoluteUri;
try {
x = svc1.IncrementSessionCounterX();
}
// catch the "redirect" that happens with cookieless sessions
catch (System.Net.WebException we) {
// We need an HttpWebResponse to check the HTTP status code.
if (typeof(System.Net.HttpWebResponse).IsInstanceOfType(we.Response)) {
System.Net.HttpWebResponse resp= (System.Net.HttpWebResponse)
we.Response;
if (resp.StatusCode == System.Net.HttpStatusCode.Found) {
// This is a "302 Found" response. Prompt the user
// to see if it is okay to redirect.
System.Windows.Forms.DialogResult dr=
System.Windows.Forms.MessageBox.Show
( String.Format("Ok to Redirect to {0}?",
resp.Headers["Location"]),
"Confirm Redirect?",
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
if (dr == System.Windows.Forms.DialogResult.Yes) {
// grab the new location specified in the response
webServiceUrl = new Uri(webServiceUrl, resp.Headers["Location"]);
button1_Click(sender, e) ; // re-invoke self
return ;
}
}
}
throw(we); // we didn't understand the exception - so throw it
}
this.textBox1.Text = x.ToString();
}
 

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