MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HttpWebRequest.GetRequestStream and ProtocolViolationExcepti

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> Compact Framework
Author Message
Ben



Joined: 31 Jan 2008
Posts: 1

PostPosted: Thu Jan 31, 2008 3:31 pm    Post subject: HttpWebRequest.GetRequestStream and ProtocolViolationExcepti Reply with quote

I'm working on an application that I would like to get running on a
WM6 Smartphone. The application needs to be able to send HTTPS POST
requests with Content-Type text/xml

This is the code I am using to send the request:

wRequest =
(HttpWebRequest)WebRequest.Create(string.Concat(this.URLPrefix,
this.Hostname, path));
wRequest.AllowWriteStreamBuffering = true;
wRequest.Method = "POST";
wRequest.ContentType = "text/xml";
wRequest.Credentials = new NetworkCredential(this.Username,
this.Password);

using (StreamWriter writer = new
StreamWriter(wRequest.GetRequestStream()))
{
writer.WriteLine(request);
writer.Close();
}

wResponse = (HttpWebResponse)wRequest.GetResponse();


This code runs fine when compiled with the .NET Framework 2.0, and
runs fine compiled with .NET Compact Framework 2.0 and running on my
desktop system (Windows XP SP2). When running on my Smartphone or the
Windows Mobile 6 platform emulator it raises an uncatchable
ProtocolViolationException every time.

ProtocolViolationException
An error message cannot be displayed because an optional resource
assembly containing it cannot be found

at
System.Net.HttpWebRequest.startGetRequestStream()
at
System.Net.HttpWebRequest.GetRequestStream()
at
MyClass.SendRequest()

I've read through many older posts and found out that I needed to
enable AllowWriteStreamBuffering when sending a POST request and close
the StreamWriter before calling GetResponse, but those changes haven't
solved the problem.

Is there something else that I am obviously doing wrong? This is the
first time I've written an application for the Compact Framework so
I'm not at all familiar with its peculiarities.

-Ben

Archived from group: microsoft>public>dotnet>framework>compactframework
Back to top
View user's profile Send private message
Jin Chang



Joined: 15 Nov 2007
Posts: 10

PostPosted: Fri Feb 01, 2008 3:45 am    Post subject: Re: HttpWebRequest.GetRequestStream and ProtocolViolationExc Reply with quote

On Jan 31, 1:31 pm, Ben wrote:
> I'm working on an application that I would like to get running on a
> WM6 Smartphone. The application needs to be able to send HTTPS POST
> requests with Content-Type text/xml
>
> This is the code I am using to send the request:
>
> wRequest =
> (HttpWebRequest)WebRequest.Create(string.Concat(this.URLPrefix,
> this.Hostname, path));
> wRequest.AllowWriteStreamBuffering = true;
> wRequest.Method = "POST";
> wRequest.ContentType = "text/xml";
> wRequest.Credentials = new NetworkCredential(this.Username,
> this.Password);
>
> using (StreamWriter writer = new
> StreamWriter(wRequest.GetRequestStream()))
> {
> writer.WriteLine(request);
> writer.Close();
>
> }
>
> wResponse = (HttpWebResponse)wRequest.GetResponse();
>
> This code runs fine when compiled with the .NET Framework 2.0, and
> runs fine compiled with .NET Compact Framework 2.0 and running on my
> desktop system (Windows XP SP2). When running on my Smartphone or the
> Windows Mobile 6 platform emulator it raises an uncatchable
> ProtocolViolationException every time.
>
> ProtocolViolationException
> An error message cannot be displayed because an optional resource
> assembly containing it cannot be found
>
> at
> System.Net.HttpWebRequest.startGetRequestStream()
> at
> System.Net.HttpWebRequest.GetRequestStream()
> at
> MyClass.SendRequest()
>
> I've read through many older posts and found out that I needed to
> enable AllowWriteStreamBuffering when sending a POST request and close
> the StreamWriter before calling GetResponse, but those changes haven't
> solved the problem.
>
> Is there something else that I am obviously doing wrong? This is the
> first time I've written an application for the Compact Framework so
> I'm not at all familiar with its peculiarities.
>
> -Ben

Read the following for a possible solution. It should work for you
since it works for me.

http://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx

- Jin

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
httpwebrequest As best I can figure this should return me something from the host but it hangs on RESPONSE = Any ideas? Private Sub sender As ByVal e As Handles Button1.Click Dim REQUEST As Net.H

HttpWebRequest using Certificates Hi everybody, my VB.NET (Framework 2.0) client application has to do a (for reading web-pages and downloading files) on a web server. The server uses a self-signed certifiacte and the client application should also use a self-signed certifi

System.Net.HttpWebRequest in C++ I added this sample code to my program: string lcUrl = // *** Establish the request loHttp = I am getting the following error: error C2065:

HttpWebRequest POST with headers and DATA in same network pa I’m making a class to POST something on a web page that needs the headers and data to be in the same package. I have tried the following but nothing helps(I always get a packet with headers and one with data).

Slow Response WSE 3.0 I'm seeing a 2-3 second delay with services running under WSE 3.0 with UsernameToken manager. I saw the posting for "Huge Delay" and checked my diagnostics setting - it was disabled. I did notice that if I put in a bogus the Security Fa
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> Compact Framework All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group