Consuming NOAA and Avoiding Protocol Violation in .Net

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. 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.

  2. 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.

  3. omegaman says:

    it appears that this blog cannot handle html comments
    abc

  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)

Leave a Reply