The server committed a protocol violation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.ToString());
}
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
.



Relevant Pages

  • Re: An existing connection was forcibly closed by the remote host
    ... Within my web service proxy class I overrode the GetWebRequestmethod and modified it as shown below. ... HttpWebRequest request = base.GetWebRequestas ... If the size of the request message I was using is greater than the size of the packets the host could receive and the host is configured receive chunked messages then I guess I can assume when we sent a message larger than the packet size without sending it chunked their server terminated the session because it was waiting for another TCP message??? ... at System.Net.Sockets.NetworkStream.Read(Bytebuffer, Int32 offset, Int32 size) ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: The server committed a protocol violation
    ... Response -> ... instead sending a new request right away. ... One potential gotcha here is that the web server does one sendfor ... application can access the web service without any problems. ...
    (microsoft.public.windowsce.embedded)
  • Re: BizTalk 2004 SOAP Adapter Tuning, ThreadPool
    ... > either the web service or the host, ... >>a result the connection is timing out. ... >>it executes the request in just a few seconds so you ...
    (microsoft.public.biztalk.general)
  • RE: Breakpoint on a web service
    ... First let us clarify how the website works. ... hosted in a web server process. ... Development Server in Visual Studio, Visual Studio will create built-in web ... I suppose that your website and web service are all ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: BizTalk 2004 SOAP Adapter Tuning, ThreadPool
    ... either the web service or the host, ... BUT i dont believe it is the right way of doing it, ... >second, third, ..., request all executing the same web ...
    (microsoft.public.biztalk.general)