zoukankan      html  css  js  c++  java
  • wcf消息契约

    image

    1.最多一个参数和一个返回值,返回值和参数的类型都是消息类型。

    image

    image

    下面的代码为定义一个消息契约的实例

    [MessageContract]
       public class MyMessage
       {
           private string operation;
           private double n1;
           private double n2;
           private double result;

           //Constructor - create an empty message.

           public MyMessage() {}

           //Constructor - create a message and populate its members.

           public MyMessage(double n1, double n2, string operation, double result)
           {
               this.n1 = n1;
               this.n2 = n2;
               this.operation = operation;
               this.result = result;
           }

           //Constructor - create a message from another message.

           public MyMessage(MyMessage message)
           {
               this.n1 = message.n1;
               this.n2 = message.n2;
               this.operation = message.operation;
               this.result = message.result;
           }

           [MessageHeader]
           public string Operation
           {
               get { return operation; }
               set { operation = value; }
           }

           [MessageBodyMember]
           public double N1
           {
               get { return n1; }
               set { n1 = value; }
           }

           [MessageBodyMember]
           public double N2
           {
               get { return n2; }
               set { n2 = value; }
           }

           [MessageBodyMember]
           public double Result
           {
               get { return result; }
               set { result = value; }
           }

           [MessageHeader(MustUnderstand=true)]
           public string str;

       }
    消息契约中使用数组对应的消息格式。

    image

    image

    下面例子是消息契约中使用自定义类型:

    1.使用数据契约定义一个类型

    2.在消息契约把数据契约作为消息契约的一部分(使用MessageHeader或MessageBodyMember)

    关于消息加密

    image

    1、消息头自己决定自己

    2、消息正文部分由最低保护级别,即下面的使用EncrypAndSign.

    image

    image

    意上述主要是针对标头来说的

    提高性能的方法:把消息契约的头和身子封装到一个类中,再对类使用消息契约。

    image

    改进后

    image

    header中的MustUnderstand必须在客户端和服务端一致。

  • 相关阅读:
    (二)Knockout 文本与外观绑定
    Knockout案例: 全选
    (一)Knockout 计算属性
    打造Orm经典,创CRUD新时代,Orm的反攻战
    让我们开启数据库无Linq、零sql时代
    EF总结
    高性能Web系统设计方案(初稿目录),支持者进
    Bootstrap+angularjs+MVC3+分页技术+角色权限验证系统
    .NET 2.0 检测
    C# 用代码创建 DataSet 和 DataTable 的列和记录
  • 原文地址:https://www.cnblogs.com/lzhp/p/3501173.html
Copyright © 2011-2022 走看看