我有一个使用netMsmqBinding的WCF服务,用于将Msmq<string>的消息添加到队列中。消息可以很好地添加,我可以通过计算机管理控制台在队列中看到它们。
我有另一个WCF服务,它试图从队列中检索消息,这就是我遇到问题的地方。每当将消息添加到队列中时,我的服务中的方法就会被调用(该位很好),但是Msmq<string>消息似乎都是空值。
我不知道我怎么能从那个Msmq<string>那里得到信息?这是我的服务细节..。任何帮助都很感激..。
[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
}
}发布于 2011-02-25 05:43:02
我认为您还没有完全“理解”WCF在MSMQ上的概念。
当在netMsmqBinding中使用WCF时,整个想法是不需要处理MSMQ的细节--让WCF运行时处理这个问题!
因此,基本上,您的方法应该与任何WCF服务一样:
contract)
[DataContract],并使用服务中的
)。
所以你的服务应该是:
[DataContract]
public class Customer
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Name { get; set; }
...
}
[ServiceContract]
public interface ICustomerService
{
[OperationContract(IsOneWay=true)]
void SaveCustomer(Customer myCustomer)
[OperationContract(IsOneWay=true)]
void CreateCustomer(int ID, string name);
}您应该有一个数据契约来描述您的数据--只需要您的数据,这里不需要MSMQ详细信息!然后,您应该有一组处理Customer对象的服务方法--您可以将它放入队列中进行存储,创建一个新的方法等等。
然后,您将为该服务契约实现客户端和服务器端,而WCF运行时将处理MSMQ传输的所有细节,将有效负载( Customer对象)放入MSMQ消息并再次将其取出等等.你没必要这么做,真的。
https://stackoverflow.com/questions/5113885
复制相似问题