首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从MSMQ反序列化使用WCF和NetMsmqBinding入队的对象图

从MSMQ反序列化使用WCF和NetMsmqBinding入队的对象图
EN

Stack Overflow用户
提问于 2011-12-07 12:30:46
回答 2查看 1.2K关注 0票数 0

我做了一些工作,使用MSMQ与WCF和NetMsmqBinding来生成消息,并在它们到达时将它们出队。我还通过使用对象图作为消息正文来标准化我的解决方案。此对象包含元数据和内部有效负载。

我想构建一个管理工具,可以监视队列和窥视消息的内容。到目前为止,我还没有成功地弄清楚如何使用System.Messaging库将Message.Body反序列化为对象图。

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-08 00:40:05

您是否有更改WCF服务绑定的作用域?

如果使用MsmqIntegrationBinding而不是netMsmqBinding,则可以在绑定中指定一系列格式化程序选项。例如

代码语言:javascript
复制
<service name="MyQueueListenner">

    <!-- Active X endpoint -->
    <endpoint address="msmq.formatname:DIRECT=OS:.\private$\myQueue"
              binding="msmqIntegrationBinding"
              bindingConfiguration="ActiveXBinding"
              contract="MyContract" />

    <!-- .Net endpoint-->
    <endpoint address="msmq.formatname:DIRECT=OS:.\private$\myOtherQueue"
              binding="msmqIntegrationBinding"
              bindingConfiguration="DotNetBinding"
              contract="MyContract" />

  </service>
  ...

  <msmqIntegrationBinding>
    <binding serializationFormat="ActiveX" name="ActiveXBinding" durable="false" exactlyOnce="false">
      <security mode="None" />
    </binding>
    <binding serializationFormat="Xml" name="DotNetBinding" durable="false" exactlyOnce="false">
      <security mode="None" />
    </binding>
  </msmqIntegrationBinding>

这允许您使用全系列的格式化程序,从而提供与基于System.Messaging的嗅探器的最大范围的互操作性。

完整的值列表在这里:http://msdn.microsoft.com/en-us/library/system.servicemodel.msmqintegration.msmqmessageserializationformat.aspx

票数 1
EN

Stack Overflow用户

发布于 2012-11-08 07:48:50

我知道这很旧,但是要序列化和支持任何对象,您可以执行以下操作:

//示例

代码语言:javascript
复制
enter code here

public person class
{
public int Id {get;set;}
public string Name {get;set;}

 public static person Desserialize(byte[] data)
        {
            person result = new person ();
            using (MemoryStream m = new MemoryStream(data))
            {
                using (BinaryReader reader = new BinaryReader(m))
                {
                    result.id = reader.ReadInt32();
                    result.Name = reader.ReadString();

                }
            }
            return result;
        }



public byte[] Serialize()
        {
            using (MemoryStream m = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(m))
                {
                    writer.Write(id);
                    writer.Write(Name);

                }
                return m.ToArray();
            }
        }

//可以做Byte[] w_byte = Person.serialize();

Person _Person = Person.Desiserile(w_byte);}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8410408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档