C# WCF以流形式输入巨大的XML,内容类型为:XML/text

C# WCF以流形式输入巨大的XML,内容类型为:XML/text,c#,wcf,C#,Wcf,我有一个RESTfulWCFWeb服务,它使用POST方法处理以流形式传入的巨大XML文件,其标题内容类型为text/text。当客户端尝试使用标题内容类型为text/xml的此web服务时,会收到“…包含无法识别的http正文格式值“xml”。预期的正文格式值为“Raw”。这可能是因为尚未在绑定上配置WebContentTypeMapper”错误。 我的任务是使此web服务使用标题内容类型:text/xml,因为许多客户端将此web服务与其他服务一起使用,并且不希望仅为此服务更改内容类型。如何

我有一个RESTfulWCFWeb服务,它使用POST方法处理以流形式传入的巨大XML文件,其标题内容类型为text/text。当客户端尝试使用标题内容类型为text/xml的此web服务时,会收到“…包含无法识别的http正文格式值“xml”。预期的正文格式值为“Raw”。这可能是因为尚未在绑定上配置WebContentTypeMapper”错误。 我的任务是使此web服务使用标题内容类型:text/xml,因为许多客户端将此web服务与其他服务一起使用,并且不希望仅为此服务更改内容类型。如何将传入流映射为WebContentFormat.Raw并使此web服务接受内容类型:text/xml?
谢谢。

我通过创建一个从WebContentTypeMapper派生的新类,并在内容类型为“text/xml”时将WebContentFormat更改为“Raw”,解决了这个问题。与这个新类一起,我更新了web.config以使用“bindings”下的“customBinding”元素

public class XmlContentTypeMapper : WebContentTypeMapper
{
    public override WebContentFormat
               GetMessageFormatForContentType(string contentType)
    {
        if (contentType.Contains("text/xml") ||  contentType.Contains("application/xml"))
        {
            return WebContentFormat.Raw;
        }
        else
        {
            return WebContentFormat.Default;
        }
    }
}
web.config

<bindings>
  <customBinding>
    <binding name="XmlMapper">
      <webMessageEncoding webContentTypeMapperType="Lt.Trigger.XmlContentTypeMapper, ExService" />
      <httpTransport manualAddressing="true" />
    </binding>
  </customBinding>
</bindings>