By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

The server committed a protocol violation

P: n/a
A little background:

I've been using web services successfully for a while now. My web server is a Windows CE 4.2 device
and my client is a windows C# application created with Visual Studio 2003. My web server has both
NTLM and Basic authentication. By providing the Credentials for my web service call, my
application can access the web service without any problems.

The problem:

I recently created a new application with Visual Studio 2005 using the same logic. However, when I
try to call the web service, I get a WebException with following message:

"The server committed a protocol violation. Section=ResponseStatusLine"

As soon as I disable the authentication on the web server, the web service call executes without
problems.

To pin-point my problem, I've created a simple test application which merely requests a web page
from the CE device. This test application gives the same error. Here's the code:

HttpWebRequest myWebRequest = WebRequest.Create("http://150.158.204.40/DMS/Installation Manual.htm")
as HttpWebRequest;
NetworkCredential networkCredential = new NetworkCredential("Test", "service");
myWebRequest.Credentials = networkCredential;
try
{
WebResponse myWebResponse = myWebRequest.GetResponse();
MessageBox.Show(myWebResponse.ContentLength.ToStri ng());
}
catch (WebException wex)
{
Trace.WriteLine(string.Format("Caught Exception: {0}", wex.Message));
Trace.WriteLine(string.Format("Stack: {0}", wex.StackTrace));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

I've enabled Network Tracing for this test application and I got following output (using Basic
authentication):

System.Net Verbose: 0 : [4952] WebRequest::Create(http://150.158.204.40/DMS/Installation Manual.htm)
System.Net Verbose: 0 : [4952]
HttpWebRequest#63840421::HttpWebRequest(http://150.158.204.40/DMS/Installation Manual.htm#1606441202)
System.Net Verbose: 0 : [4952] Exiting HttpWebRequest#63840421::HttpWebRequest()
System.Net Verbose: 0 : [4952] Exiting WebRequest::Create() -HttpWebRequest#63840421
System.Net Verbose: 0 : [4952] HttpWebRequest#63840421::GetResponse()
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with ServicePoint#54246671
System.Net Information: 0 : [4952] Associating Connection#25181126 with HttpWebRequest#63840421
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with ConnectStream#59408853
System.Net Information: 0 : [4952] HttpWebRequest#63840421 - Request: GET
/DMS/Installation%20Manual.htm HTTP/1.1

System.Net Information: 0 : [4952] ConnectStream#59408853 - Sending headers
{
Host: 150.158.204.40
Connection: Keep-Alive
}.
System.Net Information: 0 : [4952] Connection#25181126 - Received status line: Version=1.0,
StatusCode=401, StatusDescription=Unauthorized.
System.Net Information: 0 : [4952] Connection#25181126 - Received headers
{
Date: Tue, 11 Jul 2006 20:55:59 GMT
Connection: keep-alive
Server: Microsoft-WinCE/4.20
WWW-Authenticate: NTLM,Basic realm="Microsoft-WinCE"
Content-Type: text/html
Content-Length: 81
}.
System.Net Information: 0 : [4952] ConnectStream#56152722::ConnectStream(Buffered 81 bytes.)
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with ConnectStream#56152722
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with HttpWebResponse#43844556
System.Net Warning: 0 : [4952] HttpWebRequest#63840421::() - Resubmitting request.
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with ServicePoint#54246671
System.Net Information: 0 : [4952] Associating Connection#25181126 with HttpWebRequest#63840421
System.Net Information: 0 : [4952] Associating HttpWebRequest#63840421 with ConnectStream#26847985
System.Net Information: 0 : [4952] HttpWebRequest#63840421 - Request: GET
/DMS/Installation%20Manual.htm HTTP/1.1

System.Net Information: 0 : [4952] ConnectStream#26847985 - Sending headers
{
Authorization: Basic UEZFOnZpc2lvbg==
Host: 150.158.204.40
Connection: Keep-Alive
}.
System.Net Error: 0 : [4952] Exception in the HttpWebRequest#63840421:: - The server committed a
protocol violation. Section=ResponseStatusLine
System.Net Error: 0 : [4952] Exception in the HttpWebRequest#63840421::EndGetResponse - The server
committed a protocol violation. Section=ResponseStatusLine
A first chance exception of type 'System.Net.WebException' occurred in System.dll

When I look with Ethereal, I get following stream:

Request ->
GET /DMS/Installation%20Manual.htm HTTP/1.1
Host: 150.158.204.40
Connection: Keep-Alive

Response ->
HTTP/1.0 401 Unauthorized
Date: Tue, 11 Jul 2006 20:55:59 GMT
Connection: keep-alive
Server: Microsoft-WinCE/4.20
WWW-Authenticate: NTLM
WWW-Authenticate: Basic realm="Microsoft-WinCE"
Content-Type: text/html
Content-Length: 81

Request ->
GET /DMS/Installation%20Manual.htm HTTP/1.1
Authorization: Basic UEZFOnZpc2lvbg==
Host: 150.158.204.40
Connection: Keep-Alive

Response ->
<B>Access denied.</B><P>Client does not have access to the resource on the serverHTTP/1.0 200 OK
Date: Tue, 11 Jul 2006 20:55:59 GMT
Connection: keep-alive
Server: Microsoft-WinCE/4.20
Last-Modified: Mon, 10 Jul 2006 12:23:36 GMT
ETag: "0149baa1ba4c61:820:7"
Content-Type: text/html
Content-Length: 37462

<html>
<head>
<meta http-equiv="Content-Language" content="nl-be">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Installation Manual</title>
</head>
<body>
....

As you can see in the HTTP stream captured with Ethereal, the first request fails with an error,
because no Authentication is used. The application then tries again with an Authorization string in
the header. This request succeeds and the CE device start sending the HTML content. However, the
..NET framework seems to ignore this content and throws the WebException instead.

Note that I've already tried to add the "useUnsafeHeaderParsing" in the config file, but without
success.

Does anyone have an idea what could be causing this problem?
Or how I can further debug this problem?

I've you need more tracing, please let me now.

Regards
Kris
Jul 11 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.