3
votes

I have a new WCF service that some existing clients need to be able to communicate with.

There are some clients that are incorrectly sending the SOAP request with a Content-Type header of 'text/xml; charset=us-ascii'. At the moment, the clients themselves can't be changed.

When they send a request, they get the error message:

HTTP/1.1 415 Cannot process the message because the content type 'text/xml; charset=us-ascii' was not the expected type 'text/xml; charset=utf-8'

Is there any way to instruct the WCF service to ignore the charset of the Content-Type and assume utf-8?

1
@KScandrett This, plus a conversation with the author of the accepted answer on that forum post did the trick.DavidGouge
Glad that helped. Don't forget to post and accept your answer for others who may strike a similar issueK Scandrett

1 Answers

0
votes

This may be helpful for you, if not I will delete the answer. I think this can be used in your context, but am not quite sure since there are no other details.

A WebContentTypeMapper can be used to override the content type being sent. This is snipped of the code used in the WCF Sample sets. In this example it is taking in whatever content type that is sent in and mapping it to json, but you could adjust that to your needs.

If you don't have it already you can download the samples from WCF Samples This sample is located in ..WF_WCF_Samples\WCF\Extensibility\Ajax\WebContentTypeMapper\CS

using System.ServiceModel.Channels;

namespace Microsoft.Samples.WebContentTypeMapper
{
    public class JsonContentTypeMapper : System.ServiceModel.Channels.WebContentTypeMapper
    {
        public override WebContentFormat GetMessageFormatForContentType(string contentType)
        {
            if (contentType == "text/javascript")
            {
                return WebContentFormat.Json;
            }
            else
            {
                return WebContentFormat.Default;
            }
        }
    }
}