我有一个订单作为XDocument,我只是想把它放在消息的正文中并发送给MSMQ队列。我已经有效地序列化了订单对象,现在我只想发送它。这可能吗?如何通过MSMQ发送XDocument(使用WCF)?
我在这里使用WCF,但我很高兴与普通的旧msmq解决方案。我在这里得到一个错误,指出XDocument不能被序列化......显然不能这样做,但是如何让我的XDocument进入消息体呢?我是否需要推出自己的串行器?
public void SendOrder(XDocument order)
{
var address = new EndpointAddress(@"msmq.formatname:DIRECT=OS:myServer\private$\myQueue");
var binding = new MsmqIntegrationBinding();
binding.Security.Mode = MsmqIntegrationSecurityMode.None;
binding.ExactlyOnce = false;
binding.Durable = false;
var channelFactory = new ChannelFactory<IOrderSubmitter>(binding, address);
var channel = channelFactory.CreateChannel();
var message = new MsmqMessage<XDocument>(order);
message.Label = "Really Big Order with lots of profit";
message.BodyType = (int)System.Runtime.InteropServices.VarEnum.VT_ARRAY;
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
channel.SubmitOrder(message);
scope.Complete();
}
}
[ServiceContractAttribute(Namespace = "http://my.namespace.com", Name = "Hello")]
public interface IOrderSubmitter
{
[OperationContract(IsOneWay = true)]
void SubmitOrder(MsmqMessage<XDocument> message);
}
我试过之前,我在这里发布的问题,但它包装整个事情在标记。我需要与XDoc中完全相同的xml ... –
autonomatt
2010-07-19 08:13:38