代码之家  ›  专栏  ›  技术社区  ›  mhenrixon

wcf-流参数缺少crlf的cr

  •  1
  • mhenrixon  · 技术社区  · 15 年前

    我遇到的问题是,客户机正在以流的形式向我发送一个数据字符串。然后,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实现,或者是否可以以某种方式将“修复”添加到设置中?

    这似乎是一个非常讨厌的bug与wcf xmlDictionaryReader 当wcf将传入流序列化为 Message 删除(crlf)中的所有回车实例,并用lf替换。根据 this 这是wcf中的已知错误。 编辑 我向微软报告这是一个错误: https://connect.microsoft.com/wcf/feedback/details/532196/xmldictionaryreader-is-normalizing-incoming-stream-removing-cr-of-crlf#details

    1 回复  |  直到 15 年前
        1
  •  1
  •   mhenrixon    15 年前

    这似乎解决了这个问题:

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

    我想这是有意义的,因为这会导致参数不被包装或类似的事情。