PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework Mobile Application goes offline

Reply

Mobile Application goes offline

 
Thread Tools Rate Thread
Old 30-11-2006, 10:44 AM   #1
kshama.bafna@gmail.com
Guest
 
Posts: n/a
Default Mobile Application goes offline


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

  Reply With Quote
Old 30-11-2006, 12:22 PM   #2
vikash
Guest
 
Posts: n/a
Default Re: Mobile Application goes offline

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

kshama.bafna@gmail.com wrote:
> 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


  Reply With Quote
Old 30-11-2006, 01:58 PM   #3
kshama.bafna@gmail.com
Guest
 
Posts: n/a
Default Re: Mobile Application goes offline

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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off