代码之家  ›  专栏  ›  技术社区  ›  Bob Moore

WCF类型冲突

  •  1
  • Bob Moore  · 技术社区  · 16 年前

    我对WCF有问题。我想我明白问题所在,但我需要 解决方法或替代方法。请耐心听我说:这是一个相当大的数字

    其基础是,我为每种消息类型都有一个类,以及一个泛型类 因为传递它只占用与最大大小消息相同的空间。

    接收QOD_Message,将其转换为泛型类型以供发送。接收者事件 与消息类型具有一对一关系的成员。

    public class QOD_Message_Minimal
    {
       a message header
    }
    
    public class QOD_Message : QOD_Message_Minimal
    {
       generic message - defines an empty body
    }
    
    public class QOD_WcfDialout : QOD_Message_Minimal
    {
       ... some irrelevant code
    
       // cast operators to convert to and from the abstract message class.
    
       public static implicit operator QOD_Message (QOD_WcfDialout m)
       {
          ... some irrelevant code
       }
    
       public static implicit operator QOD_WcfDialout (QOD_Message m)
       {
          ... some irrelevant code
       }
    }
    

    请注意铸造操作员。

    现在问题来了。我想扩展这个接口以支持WCF,所以 (固定)收件人。

    派遣。因此,WCF代码看起来与正常的消息传递非常相似

    [ServiceContract]
    public interface IDialout
    {
       [OperationContract (IsOneWay = true)]
       void Dialout (string NumberToDial);
    
       [OperationContract (IsOneWay = true)]
       void Dispatch (QOD_Message msg);
    }
    

    WCF客户端和的代理代码。…哦。客户端无法编译。

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="QOD_Message_Minimal", Namespace="http://schemas.datacontract.org/2004/07/QOD_Messaging")]
    [System.Runtime.Serialization.KnownTypeAttribute(typeof(QOD_Messaging.QOD_Message))]
    public partial class QOD_Message_Minimal : object, System.Runtime.Serialization.IExtensibleDataObject
    {
       whole slew of data members.
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name="QOD_Message", Namespace="http://schemas.datacontract.org/2004/07/QOD_Messaging")]
    public partial class QOD_Message : QOD_Messaging.QOD_Message_Minimal
    {
       extra stuff to define the added body.
    }
    

    所以。。。。。

    程序集的类型定义,并使用代理定义。..并且无法编译。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Marc Gravell    16 年前

    转换运算符不是生成的mex的一部分,因此它们在客户端不存在。

        2
  •  1
  •   John Saunders    10 年前

    可以将类方法作为web服务运算符公开,也可以将类作为数据契约或故障契约公开,以XML模式公开,将消息契约公开为消息类型。没有其他东西可以暴露。

    推荐文章