K
kshama.bafna
Hi,
We are running into some strange scenarios related to HTTP Web Requests
made
programmatically from a Mobile application. Following is the scenario:
The application connects to the server through the webservice to
download
the data. We are facing issues with the application going offline
intermittently. It is observed that while making HTTP Requests to the
webservice for data / queries one of the requests fails (abrupt
behavior,
not specific to any query). This is because the response to the HTTP
Request
returns an authorization failed exception (HTTP 401 - unauthorized
access).
After this, the application cannot make any HTTP Requests to the
webservice.
Following is a sample code that is used for making the HTTP requests.
It
seems quite strange that the response fails intermittently due to
Unauthorized access exception. Although the application goes offline,
the browsing through Pocket IE is still possible. Any pointers as to
how we can handle this issue??
Testing Scenarios:
1. Using ActiveSync 4.1 (Build 4841) and 4.2 to connect to PC
2. Windows Mobile 5.0 PDA
Code:
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
try
{
webRequest = (HttpWebRequest)WebRequest.Create(new Uri(m_WSUri));
webRequest.Credentials = new NetworkCredential(m_UserName,
m_Password);
webRequest.Method = "POST";
webRequest.KeepAlive = false;
webRequest.ContentType = "text/xml";
webRequest.ContentLength = SOAP_ENV.Length;
webRequest.Headers.Add("SOAPAction: http://tempuri.org/IsAlive");
webRequest.AllowWriteStreamBuffering = true;
webRequest.AllowAutoRedirect = true;
webRequest.Proxy = WebProxy.GetDefaultProxy();
StreamWriter requestStream = new
StreamWriter(webRequest.GetRequestStream());
requestStream.Write(SOAP_ENV);
requestStream.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseStreamReader = new
StreamReader(responseStream);
string response = responseStreamReader.ReadToEnd();
responseStreamReader.Close();
responseStream.Close();
webResponse.Close();
XmlDocument responseXml = new XmlDocument();
responseXml.LoadXml(response);
errToCheckNetCredentials = ErrorType.NO_ERROR;
if(responseXml.GetElementsByTagName("IsAliveResult")[0].InnerXml ==
"true")
return true;
return false;
}
catch(Exception e)
{
Logger.GetLogger().AddLog(e.ToString());
return false;
}
finally
{
if(webRequest != null)
webRequest.Abort();
webRequest = null;
webResponse = null;
}
Thanks,
Kshama
We are running into some strange scenarios related to HTTP Web Requests
made
programmatically from a Mobile application. Following is the scenario:
The application connects to the server through the webservice to
download
the data. We are facing issues with the application going offline
intermittently. It is observed that while making HTTP Requests to the
webservice for data / queries one of the requests fails (abrupt
behavior,
not specific to any query). This is because the response to the HTTP
Request
returns an authorization failed exception (HTTP 401 - unauthorized
access).
After this, the application cannot make any HTTP Requests to the
webservice.
Following is a sample code that is used for making the HTTP requests.
It
seems quite strange that the response fails intermittently due to
Unauthorized access exception. Although the application goes offline,
the browsing through Pocket IE is still possible. Any pointers as to
how we can handle this issue??
Testing Scenarios:
1. Using ActiveSync 4.1 (Build 4841) and 4.2 to connect to PC
2. Windows Mobile 5.0 PDA
Code:
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
try
{
webRequest = (HttpWebRequest)WebRequest.Create(new Uri(m_WSUri));
webRequest.Credentials = new NetworkCredential(m_UserName,
m_Password);
webRequest.Method = "POST";
webRequest.KeepAlive = false;
webRequest.ContentType = "text/xml";
webRequest.ContentLength = SOAP_ENV.Length;
webRequest.Headers.Add("SOAPAction: http://tempuri.org/IsAlive");
webRequest.AllowWriteStreamBuffering = true;
webRequest.AllowAutoRedirect = true;
webRequest.Proxy = WebProxy.GetDefaultProxy();
StreamWriter requestStream = new
StreamWriter(webRequest.GetRequestStream());
requestStream.Write(SOAP_ENV);
requestStream.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse();
Stream responseStream = webResponse.GetResponseStream();
StreamReader responseStreamReader = new
StreamReader(responseStream);
string response = responseStreamReader.ReadToEnd();
responseStreamReader.Close();
responseStream.Close();
webResponse.Close();
XmlDocument responseXml = new XmlDocument();
responseXml.LoadXml(response);
errToCheckNetCredentials = ErrorType.NO_ERROR;
if(responseXml.GetElementsByTagName("IsAliveResult")[0].InnerXml ==
"true")
return true;
return false;
}
catch(Exception e)
{
Logger.GetLogger().AddLog(e.ToString());
return false;
}
finally
{
if(webRequest != null)
webRequest.Abort();
webRequest = null;
webResponse = null;
}
Thanks,
Kshama