【问题标题】:WCF - Stream parameter is missing CR of CRLFWCF - 流参数缺少 CRLF 的 CR
【发布时间】:2010-02-08 12:36:26
【问题描述】:

我遇到的问题是客户端正在向我发送一串数据作为流。然后 WCF 进行规范化(删除 CRLF 的 CR 部分),我在该特定字符串上得到服务器和客户端之间的哈希不匹配。

    public void SomeWcfContract(Stream input)
    {
        try
        {
            string processed = ReadStream(input);
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
        }
        catch (Exception ex)
        {
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError;
        }
    }


    private string ReadStream(Stream input)
    {
        string output;

        using (var reader = new StreamReader(input, Encoding.UTF8))
        {
            output = reader.ReadToEnd();
        }

        return output;
    }

我在这里读到了一篇关于这个的帖子:XML deserialization 'standardising' line endings, how to stop it? (.NET)

这与我遇到的问题完全相同,但我使用的是 WCF 的标准 XmlSerializer。我需要创建自己的 XmlSerializer 实现,还是可以以某种方式将“修复”添加到设置中?

这似乎是 WCF XmlDictionaryReader 的一个非常讨厌的错误,当 WCF 将传入流序列化为 Message 时,所有回车符 (CRLF) 的实例都被删除和替换与LF。根据this,这是 WCF 中的一个已知错误。 编辑我将此作为错误报告给 Microsoft:https://connect.microsoft.com/wcf/feedback/details/532196/xmldictionaryreader-is-normalizing-incoming-stream-removing-cr-of-crlf#details

【问题讨论】:

    标签: c# wcf xml-serialization


    【解决方案1】:

    这似乎解决了这个问题:

        [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, 
            UriTemplate = UriTemplates.SomeWcfContract), OperationContract]
        void SomeWcfContract(Stream vcard);
    

    我想这是有道理的,因为这会导致参数不被包装或类似的东西。

    【讨论】:

      猜你喜欢
      • 2019-11-18
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      相关资源
      最近更新 更多