使用 netMsmqBinding 读取消息的 WCF Msmq 问题
我有一个使用 netMsmqBinding 的 WCF 服务,我用它来将 Msmq
消息添加到队列中。消息添加得很好,我可以通过计算机管理控制台在队列中看到它们。
我有另一个 WCF 服务正在尝试从队列中检索消息,这就是我遇到问题的地方。每当将消息添加到队列中时(该位工作正常),我的服务中的方法就会被调用,但 Msmq
消息似乎全部为空值。
我不确定如何从 Msmq
获取消息?这是我的服务详细信息...任何帮助表示赞赏..
[ServiceContract]
[ServiceKnownType(typeof(Msmq<string>))]
public interface IMessageListener
{
[OperationContract(IsOneWay = true, Action = "*")]
void ListenForMessage(Msmq<string> msg);
}
public class MessageListener : IMessageListener
{
[OperationBehavior(TransactionScopeRequired = false, TransactionAutoComplete = true)]
public void ListenForMessage(MsmqMessage<string> msg)
{
//this gets called and seems to remove the message from the queue, but message attributes are all null
}
}
I have a WCF service using netMsmqBinding that I am using to add messages of Msmq<string>
to a queue. The messages are added fine and I can see them in the queue via the computer management console.
I have another WCF service that is trying to retrieve the messages from the queue, this is where I'm having a problem. My method in my service is getting called whenever a message is added to the queue (that bit is working fine) but the Msmq<string>
message seems to have all null values.
I'm not sure how I can get the message from that Msmq<string>
? Here is my service details... any help appreciated..
[ServiceContract]
[ServiceKnownType(typeof(Msmq<string>))]
public interface IMessageListener
{
[OperationContract(IsOneWay = true, Action = "*")]
void ListenForMessage(Msmq<string> msg);
}
public class MessageListener : IMessageListener
{
[OperationBehavior(TransactionScopeRequired = false, TransactionAutoComplete = true)]
public void ListenForMessage(MsmqMessage<string> msg)
{
//this gets called and seems to remove the message from the queue, but message attributes are all null
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您还没有完全“理解”WCF over MSMQ 的想法。
当将 WCF 与 netMsmqBinding 结合使用时,整个想法是您不需要需要处理 MSMQ 的详细信息 - 让 WCF 运行时处理它!
所以基本上,您的方法应该与任何 WCF 服务一样:
[DataContract]
并在您的服务方法中使用这些结构因此,您的服务应该类似于:
您应该有一个数据合同来描述您的数据 - 只是您的数据,这里不需要 MSMQ 详细信息!然后您应该有一组处理
Customer
对象的服务方法 - 您可以将其放入队列中进行存储、创建一个新的等。然后您将实现客户端和服务器端对于此服务协定,WCF 运行时将处理 MSMQ 传输的所有细节,将有效负载(
Customer
对象)放入 MSMQ 消息中,然后再次将其取出,等等...真的不必处理这个问题。I think you're not quite "getting" the idea of WCF over MSMQ.
When using WCF with the netMsmqBinding, the whole idea is that you don't need to deal with the details of MSMQ - let the WCF runtime handle that!
So basically, your approach should be as with any WCF service:
[DataContract]
and use those in your service methodsSo your service should be something like:
You should have a data contract to describe your data - just your data, no MSMQ details needed here! Then you should have one set of service methods that will deal with the
Customer
object - you can put it into the queue for storing, create a new one etc.You would then implement the client and the server side for this service contract, and the WCF runtime will handle all the details of MSMQ transport, putting the payload (the
Customer
object) into a MSMQ message and getting it back out again and so on... you don't have to deal with that, really.