WCF SOAP Service Ignore Content-Type Encoding

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

There are several clients that incorrectly send a SOAP request with the Content-Type header 'text / xml; Charset = US-ASCII. At the moment, the clients themselves cannot be changed.

When they submit a request, they receive an error message:

HTTP / 1.1 415 Unable to process message because content type 'Text / XML; charset = us-ascii' was not the expected type text / xml; encoding = UTF-8 '

Can I tell WCF service to ignore Content-Type encoding and accept utf-8?

+3


source to share


1 answer


It might be helpful to you if I don't delete the answer. I think it can be used in your context, but I'm not entirely sure as there are no other details.

WebContentTypeMapper can be used to override the submitted content type. This is detached from the code used in WCF sample sets. In this example, it accepts any content type that is submitted and maps it to json, but you can customize it to your needs.



If you don't have it, you can download samples from WCF Samples This sample is in the file .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;
            }
        }
    }
}

      

0


source







All Articles