我有一個訂單作爲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