2010-07-16 6 views
2

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); 
} 

답변

1

Windows 7 상자에서 같은 문제가 발생합니다. 그것은 내 XML 문자열을 다른 XML 안에 넣고있다. 서버 2003에서는 모든 것이 잘 작동합니다.

나는 마침내 이것을 고칠 수있었습니다. 이 작업을 수행하는 데는 두 가지 방법이있는 것 같습니다. 둘 다 Formatter를 XmlMessageFormatter로 설정해야합니다. MessageQueue에 포매터를 설정하거나 보내고 받기 전에 메시지를 설정할 수 있습니다.

messageQueue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(System.String) }); 
2

XDocument는 XML 데이터에 대한 편리한 래퍼입니다. XDocument를 직렬화 할 필요가 없습니다. XML 데이터를 문자열로 보내면됩니다. XDocument.ToString()

+0

여기에 질문을 게시하기 전에 시도했지만, 모든 내용이 태그로 묶여 있습니다. XDoc에있는 그대로 XML이 필요합니다 ... – autonomatt

관련 문제