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.

About these ads
  1. #1 by veeru on February 14, 2013 - 2:50 pm

    Thanks a ton buddy.. God bless :)

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

    thanks so much for sharing..

  3. #3 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!

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

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

    Thanks a bunch. Extremely helpful.

  6. #6 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!!!!

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

    This saved my day!

    Thank you very much for sharing =)

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

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

  9. #9 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!

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

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

    Cheers, Erik!

  12. #12 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!

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

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

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

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

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

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

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

    Thank you so much. This helped tremendously.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: