Web Service “content type” Error using Visual Studio 2008


This is obvious in retrospect, but I am blogging this in case anyone else comes across the same problem.

 

When writing my first VS 2008 Windows Forms app that used a Web Service, after adding the service reference and the code to talk to it, I repeatedly received the following error:

The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8).

Googling this was frustrating; nothing was related, although I did go down a few blind alleys trying things I found on a couple sites. I spent an hour or two Googling and using the .NET Encoding converters to write convoluted conversion code to change the charset, to no avail.

 

The answer turned out to be embarrassingly simple: I set the Web Service reference incorrectly.

Finally I tried consuming the Web Service from VS 2005. I noticed right away the options in the dialog to add the web service were different. And then my code just worked.

The error I received, as is often the case, had nothing to do with the actual cause of the problem.

Apparently, Microsoft, all gaga over its new WCF-style Web Services, has deeply buried the setting of references to "old-style", aka bog-standard, everyone-on-the-planet-uses-this-kind, XML Web Services. Thanks, Microsoft.

I had made the mistake of setting the reference directly in the "Add Service Reference" dialog; this is actually for the new WCF Web Services, as I discovered.

Turns out, to get a reference to an "old-style" Web Service, you need to first click the "Advanced" button in the bottom-left corner of the "Add Service Reference" dialog. Then, you need to click the "Add Web reference" button in the bottom-left corner of the "Advanced" dialog. After all that, you can properly set the reference, in the usual manner.

 

I also noticed that, magically, the next time I looked at the VS menu, there was a brand-new "Add Web Reference" option on the menu that was not there before. As if to really drive you nuts, making you think it was there all along and you just didn’t see it:

image

Note the 2 different reference options: "Add Web Reference", for adding an "old-style" Web Service reference, and "Add Service Reference", for adding a WCF Web Service reference. Could this menu be any more confusing?

 

Hopefully this will help someone else avoid the wasted time.

  1. #1 by Brayan on February 12, 2020 - 4:24 pm

    grande man !!!!!!!

  2. #2 by Luke Latham on July 15, 2014 - 3:32 pm

    Fortunately, I found your post after only a few minutes searching. Everyone should upvote/Tweet/FB this to help push it to the top of the search results for this issue. Thanks Andrew!

    • #3 by andrewcushen on July 16, 2014 - 9:12 pm

      Glad this is still helping people! You’re welcome, Luke.

      • #4 by Sihong on December 18, 2014 - 5:25 pm

        yes, it is still very helpful. I wasted my time before I found your post. In my case, a MS application created the dll automatically which doesn’t work for the old web services. Lucky found your post. Thanks a lot

  3. #5 by veeru on February 14, 2013 - 2:50 pm

    Thanks a ton buddy.. God bless 🙂

    • #6 by Sihong on December 18, 2014 - 5:24 pm

      yes, it is still very helpful. I wasted my time before I found your post. In my case, a MS application created the dll automatically which doesn’t work for the old web services. Lucky found your post. Thanks a lot

  4. #7 by Aradhana Sharma on December 20, 2012 - 1:30 am

    thanks so much for sharing..

  5. #8 by Ernesto Pizarro on November 9, 2012 - 2:34 pm

    Thank you for posting this! I had been searching a while just finding a bunch of post relating to the same issue but with WCF web service (go figure) and im not using WCF. All this time i was just using the wrong service reference option…thanx Microsoft for making things more confusing than they should be!

  6. #9 by Jon on November 2, 2012 - 1:56 pm

    Thank you for posting this! I had created a “normal” WCF service reference and kept getting these really bizarre errors. The most recent error involved surprisingly switching the response charset from UTF-8 (all other errors returned this charset!) to ISO-8859-1. It was crazy frustrating until I found your post.

  7. #10 by Jesse Bethke on January 3, 2012 - 6:57 pm

    Thanks a bunch. Extremely helpful.

  8. #11 by roy on December 8, 2011 - 3:52 pm

    awesome… the sun will shine today…. another website said you need to create a message encoding class… this saved me a lot of time!!!!

  9. #12 by André Lima on December 7, 2011 - 12:04 pm

    This saved my day!

    Thank you very much for sharing =)

  10. #13 by andrewcushen on October 20, 2011 - 9:02 pm

    Marc & Rich, you’re welcome, glad it helped.

  11. #14 by Marc Clifton on October 10, 2011 - 12:31 pm

    Thank you! I’ve been updating a small app for NOAA’s new URL and started from scratch. Your blog post saved the day!

  12. #15 by Rich on October 3, 2011 - 10:44 pm

    Thank you, helped me finally wrap up my issues with the national weather service.

    To all that get here…..add it as a web reference and not a service reference.

    gov.weather.graphical.ndfdXML weatherdata = new gov.weather.graphical.ndfdXML();

    C#
    ————–
    decimal lat = 47.72m;
    decimal log = -122.02m;
    gov.weather.graphical.unitType UT = new gov.weather.graphical.unitType();
    gov.weather.graphical.formatType FT = new gov.weather.graphical.formatType();
    FT = gov.weather.graphical.formatType.Item24hourly;
    UT = gov.weather.graphical.unitType.e;;
    string result = weatherdata.NDFDgenByDay(lat, log, DateTime.Now, “1”, UT, FT);

    Thanks again.

  13. #16 by andrewcushen on September 8, 2011 - 9:23 pm

    Cheers, Erik!

  14. #17 by Erik on August 30, 2011 - 12:27 am

    Thank you! And thank google for ranking your post #1 for:
    “The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8).”

    You probably saved me hours 🙂

    Cheers!

  15. #18 by Pooja on June 22, 2011 - 6:57 am

    Thanks a lot, i also got the same error and spent half hour debugging the issue and then i put the error in google and found this.
    do keep posting more solutions 🙂

    Regards,
    Pooja

  16. #19 by chen jie on November 9, 2009 - 5:10 pm

    thank you,but i had wasted 3 hours!!!

  17. #20 by Joshua on July 14, 2009 - 5:43 pm

    Thank you for blogging this. Thankfully I only spent about 45 minutes looking until I stumbled upon your post. MANY thanks

  18. #21 by Peter on June 8, 2009 - 10:15 pm

    Dude… However many months ago you wrote this, you saved me a BUNCH of trouble TONIGHT.Thanks so much. If you blog it, it’s around forever for people to learn from.

  19. #22 by Andrew on May 4, 2009 - 10:46 pm

    @No name:Glad it helped, I know it was driving *me* nuts ’til I figured it out.

  20. #23 by No name on April 28, 2009 - 5:30 pm

    Thank you so much. This helped tremendously.

Leave a reply to Jon Cancel reply