简体   繁体   English

WCF SOAP服务忽略内容类型字符集

[英]WCF SOAP Service Ignore Content-Type charset

I have a new WCF service that some existing clients need to be able to communicate with. 我有一个新的WCF服务,一些现有的客户端需要能够与之通信。

There are some clients that are incorrectly sending the SOAP request with a Content-Type header of 'text/xml; 有些客户端错误地发送带有'text / xml的Content-Type头的SOAP请求; charset=us-ascii'. 字符集= 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; HTTP / 1.1 415无法处理消息,因为内容类型为'text / xml; charset=us-ascii' was not the expected type 'text/xml; charset = us-ascii'不是预期的类型'text / xml; charset=utf-8' 字符集= UTF-8'

Is there any way to instruct the WCF service to ignore the charset of the Content-Type and assume utf-8? 有没有办法指示WCF服务忽略 Content-Type的字符集并假设utf-8?

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. WebContentTypeMapper可用于覆盖正在发送的内容类型。 This is snipped of the code used in the WCF Sample sets. 这是剪辑了WCF示例集中使用的代码。 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. 在这个例子中,它接收发送的任何内容类型并将其映射到json,但您可以根据需要进行调整。

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 如果您还没有它,可以从WCF示例下载示例此示例位于..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;
            }
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改WCF服务以接受内容类型“ application / xml; charset = utf-8” - Change WCF service to accept content-type “application/xml;charset=utf-8” 如何使WCF服务接受Content-type为“ text / xml”的肥皂消息? - How do I make my WCF service accept soap message with Content-type of “text/xml”? SILVERLIGHT WCF问题:内容类型application / soap + xml; charset = utf-8已发送到需要text / xml的服务; - SILVERLIGHT WCF Issue: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; WCF服务不喜欢我的内容类型 - WCF Service Doesn't Like My Content-Type 是否可以在不设置内容类型的情况下调用WCF服务? - Can I call a WCF service without setting content-type? WCF 4.0 Rest Service返回内容类型text / html - WCF 4.0 Rest Service returns content-type text/html 从AngularJS内容类型问题发布到WCF服务 - Posting to WCF service from AngularJS Content-type issue 期望SOAP 1.1内容类型的WCF SOAP 1.2服务 - WCF SOAP 1.2 service expecting SOAP 1.1 content type WCF 响应消息的charset=utf-8与绑定的内容类型不匹配(application/soap+xml;charset=utf-8) - WCF charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) wcf +响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8) - wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM