2017-06-22 71 views
3

我有一些新的WCF服务,一些现有的客户端需要能够与之通信。WCF SOAP服务忽略内容类型字符集

有一些客户端错误地发送SOAP请求,其Content-Type标头为'text/xml;字符集= US-ASCII”。目前,客户本身不能改变。

当他们发送一个请求,他们得到了错误消息:

HTTP/1.1 415无法处理消息,因为内容类型 “文本/ XML的; charset = us-ascii'不是预期的类型'text/xml; 的charset = UTF-8'

有什么办法来指示WCF服务忽略的内容类型的字符集,并假设UTF-8?

+0

也许https://开头的社会.msdn.microsoft.com/Forums/vstudio/zh-CN/c1a29404-c990-482a-901f-dbfdf0d8f270/how-to-config-wcf-service-to-accept-non-unicode-encoding?forum = wcf –

+0

https:/ /docs.microsoft.com/en-us/dotnet/framework/wcf/extending/custom-encoders –

+1

@KScandrett这,再加上与该论坛帖子上接受的答案的作者谈话做了伎俩。 – DavidGouge

回答

0

这可能对您有所帮助,如果不是,我会删除答案。我认为这可以在你的情况下使用,但我不太确定,因为没有其他细节。

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

如果你没有它已经可以从WCF Samples 此示例位于..WF_WCF_Samples \ WCF \扩展下载Samples \阿贾克斯\ 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; 
      } 
     } 
    } 
}