Mobile Application goes offline

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
 
V

vikash

Hello
I dont have much idea about this but it seems that the problem is from
the server side and it is not allowing access to ur client.
For checking it do use try{}.. catch{} and return the exception.
i suppose the NT authority user is not assigned access. plz do check.
i was having something similer kind of issue.
in one another problem the namespace of the webservice was troubling.

thanks n regards
vikash

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
 
K

kshama.bafna

Hi,

The Http requests are made for the same user credentials. The output
seems to be fine for initial 5-6 requests. Then suddenly the server
starts returning 401 Unauthorized Access error.

P.S: A new Http request is created each time and the same credentials
are passed to it.

Regards,
Kshama
 

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