zoukankan      html  css  js  c++  java
  • WCF步步为营(五):数据契约

    1. WCF只能传输序列化的类型,WCF 能自动序列化.net内置的之类型,但是如果需要传输自定义的类型,必须把自定义的类型标注DataContract

    image

    DataContract标注这个类作为数据契约,DataMember属性指明那些字段公布为原数据,是否必需,顺序是多少。

    2. 上面的定义,使得Student可以用在服务契约里,下面的Name可以让客户端的名称和服务端不同。

    image

    3. 下面是我们生成的代理类,可以看到客户端的名字,而且由于Student的Address未声明DataMember,所以客户端是不可见的

    Code
     

     

    4. 客户端调用示例:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.ServiceModel;

    using JackWangServiceClient.CalcService;

    namespace JackWangServiceClient

    {

        class Program

        {

            static void Main(string[] args)

            {

                CalcServiceClient proxy = new CalcServiceClient();

                long result = proxy.AddInt(50, 60);

                Student myStudent = new Student();

                myStudent.FirstName = "Jack";

                myStudent.LastName = "Wang";

                myStudent.Age = 18;

                Student resultStudent = proxy.addAgeOfStudent(myStudent);

                Console.Out.WriteLine("result from server is:" + result);

                Console.Out.WriteLine(resultStudent.FirstName + "," + resultStudent.LastName + "," + resultStudent.Age);

                Console.ReadLine();

            }

        }

    }

    扫码关注公众号,了解更多管理,见识,育儿等内容

    作者: 王德水
    出处:http://www.cnblogs.com/cnblogsfans
    版权:本文版权归作者所有,转载需经作者同意。

  • 相关阅读:
    javascript常用知识点总结
    【HOJ1356】【Miller_rabin素性测试】Prime Judge
    【POJ1568】【极大极小搜索+alpha-beta剪枝】Find the Winning Move
    【CF39E】【博弈论】What Has Dirichlet Got to Do with That?
    【BZOJ2281】【博弈论+DP】 [Sdoi2011]黑白棋
    【HDU3802】【降幂大法+矩阵加速+特征方程】Ipad,IPhone
    【POJ3243】【拓展BSGS】Clever Y
    【HDU2815】【拓展BSGS】Mod Tree
    【模板】【网络流】Dinic
    【模板】【凸包】Graham_scan
  • 原文地址:https://www.cnblogs.com/cnblogsfans/p/1234936.html
Copyright © 2011-2022 走看看