在MSMQ文件中写入以UTF8编码的XML和Bom

时间:2015-03-09 16:14:16

标签: xml vb.net utf-8 msmq

我正在尝试用msmq文件写一个带有Bom xml的UTF8,所以我创建了我自己的格式化程序(http://support.microsoft.com/kb/310683

但结果我有一个没有Bom XML的UTF8 所以我试过这个: Public Sub Write(消息为System.Messaging.Message,obj As Object)实现System.Messaging.IMessageFormatter.Write

    Dim utf8 As UTF8Encoding = New UTF8Encoding(True)
    Dim stm As Stream = New MemoryStream()
    Dim writer As StreamWriter = New StreamWriter(stm, utf8)
    writer.Write(obj.ToString())
    message.BodyStream = stm

End Sub

它有效,但它会削减我的xml,我不会关闭作者!!

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

问题是StreamWriter缓存了not being flushed

的数据
…    
writer.Write(obj.ToString())
writer.Flush();
message.BodyStream = stm