Consuming NOAA and Avoiding Protocol Violation in .Net

Posted by OmegaMan at May 28, 2007

Category: Bug Reports

In .Net 2/3 one can consume the NOAA web service WSDL at (http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl) and run into this error

Exception: System.Net.WebException
Message: The server committed a protocol violation. Section=ResponseStatusLine
Source: System.Web.Services
TargetSite: System.Net.WebResponse GetWebResponse(System.Net.WebRequest)

  To get around this issue open up the generated reference.cs file and add this to the web service proxy class and rebuild and run

protected override WebRequest GetWebRequest(Uri uri)
{
    HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
    request.ProtocolVersion = HttpVersion.Version10;
    return request;
}

Thanks goes to Rob Garret’s blog on this.

Share

5 Comments

  1. Peter Ritchie says

    Alternatively you may be able to add the following to your app.config:

    This way, if the NOA site stops having a protocol violation you don’t have to recompile your app.

    Reply
  2. Peter Ritchie says

    Alternatively you may be able to add the following to your app.config:

    This way, if the NOA site stops having a protocol violation you don’t have to recompile your app.

    Reply
  3. omegaman says

    it appears that this blog cannot handle html comments
    abc

    Reply
  4. RFish says

    Where is the “generated reference.cs” file? All I can see in VS is a .discomap and a .wsdl file. (I’m learning VS2005 right now)

    Reply
  5. omegaman says

Leave a comment

(required)
(required) (will not be published)

This site uses Akismet to reduce spam. Learn how your comment data is processed.