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

标签 wcf soap character-encoding

我有一个新的 WCF 服务,一些现有客户端需要能够与之通信。

有些客户端错误地发送了带有“text/xml”的 Content-Type header 的 SOAP 请求;字符集=us-ascii'。目前,客户本身无法更改。

当他们发送请求时,他们收到错误消息:

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'

有什么方法可以指示 WCF 服务忽略 Content-Type 的字符集并假定为 utf-8?

最佳答案

这可能对你有帮助,如果没有我会删除答案。我认为这可以在您的上下文中使用,但我不太确定,因为没有其他详细信息。

WebContentTypeMapper 可用于覆盖发送的内容类型。这是 WCF 示例集中使用的代码的片段。在此示例中,它接收发送的任何内容类型并将其映射到 json,但您可以根据需要进行调整。

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

关于WCF SOAP 服务忽略内容类型字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44698210/

相关文章:

c# - 提供的 URI 方案 'https' 无效;调用网络服务时预期为 'http'

web-services - URL 末尾不带 WSDL 的 SOAP Web 服务

python - 如何将 Python 中的多部分/相关请求发送到 SOAP 服务器?

jsf - 在 GlassFish 中将 JSF 输入提交值的请求字符编码设置为 UTF-8

c# - 在 Windows Process Activation Services (WAS) 和 IIS 7 之间进行选择

c# - 默认情况下 WCF 服务是无状态的吗?

java - 是否可以生成填充了安全 header 的 WSDL?

unicode - Unicode 可打印字符的范围是多少?

c++ - 如何将字符串从 C# 传递到 C++ 并指定编码

WCF 服务引用支持文件未更新