在 MSMQ 中发送二进制消息
在 .NET 服务中,我想在 MSMQ 消息中发送流的内容。我从 WCF 收到一个 Stream 对象(可以是图像、.doc 文件或其他任何内容),我只想将内容放入 MSMQ 中。我尝试将 System.Messaging.Message.BodyStream 属性设置为流对象,但当我尝试发送消息时收到“方法不支持”错误。
有人有关于如何做到这一点的示例或教程吗?
我正在寻找这样的东西:
消息契约:
<MessageContract()> _
Class UploadStreamMessage
<MessageHeader()> _
Public guidCaller As Guid
<MessageBodyMember()> _
Public data As Stream
End Class
然后是 WriteToMSMQ 方法实现:
<OperationBehavior(TransactionScopeRequired:=True, Impersonation:=ImpersonationOption.Required)> _
Public Sub WriteToMSMQ (ByVal stream As IServiceMSMQ.UploadStreamMessage) Implements IServiceMSMQ.WriteToMSMQ
Using queue As New MessageQueue(NOM_QUEUE)
Dim msmqMessage As New Message
msmqMessage = New System.Messaging.Message()
msmqMessage.Body = stream.data
queue.Send(msmqMessage, transaction)
stream.data.Close()
End Using
谢谢!
In a .NET service, I'd like to send the content of a stream in a MSMQ message. I receive a Stream object from WCF (which can be an image, a .doc file or anything else) and I would just like to put the content in MSMQ. I tried setting the System.Messaging.Message.BodyStream property to the stream object, but I receive a "Method not supported" error when I try to Send the message.
Does anyone have a sample or tutorial on how to do that ?
I'm looking for something like this :
Message contract :
<MessageContract()> _
Class UploadStreamMessage
<MessageHeader()> _
Public guidCaller As Guid
<MessageBodyMember()> _
Public data As Stream
End Class
And then the WriteToMSMQ method implementation :
<OperationBehavior(TransactionScopeRequired:=True, Impersonation:=ImpersonationOption.Required)> _
Public Sub WriteToMSMQ (ByVal stream As IServiceMSMQ.UploadStreamMessage) Implements IServiceMSMQ.WriteToMSMQ
Using queue As New MessageQueue(NOM_QUEUE)
Dim msmqMessage As New Message
msmqMessage = New System.Messaging.Message()
msmqMessage.Body = stream.data
queue.Send(msmqMessage, transaction)
stream.data.Close()
End Using
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我使用的电子邮件队列的示例...我认为您需要添加格式化程序。
以下是 DTO:
}
这是您需要的扩展。
这是发送机制:
这是它的接收端......
Here's an example of an email queue I use... I think you need to add a formatter.
Here are the DTOs:
}
Here is an extension you need.
This is the sending mechanism:
This is the receiving end of it...
MSMQ 不支持流式传输,因为它是明确基于消息且松散耦合的。您应该将合约字段声明为
byte[]
并在那里收集数据。MSMQ doesn't support streaming, because it is explicitly message based and loosely coupled. You should declare field of contract as
byte[]
and gather data there.