zoukankan      html  css  js  c++  java
  • 关于AutoMapper和WCF的一些认识

         现在互联网时代呈尚快速开发,快速迭代。伴随着必然产生一些好用的第三方工具,今天有幸看到了Automapper这种类似ORM的框架,但是跟ORM还不太一样,

    ORM是实体和数据库表之间的映射,而此框架主要实现实体和实体间映射,两个实体可以互相转换,即便两个实体属性名称和类型不一致也可以相互赋值,可以指定规则两个实体属性名称和个数必须一致或者忽略.

         公司最近做了一个新项目,就是基于restFul实现的WCF,最主要实现是服务契约接口方法要加属性WebInVoke,例如:

    [WebInvoke(Method = "GET", UriTemplate = "Method/{Id}"
    , RequestFormat = WebMessageFormat.Json
    , ResponseFormat = WebMessageFormat.Json)]

     FundClassBasicRecord Method(string Id);

    客户端访问方式不能采用原来的访问WCF的方式去访问服务端,否则会提示没有配置endpoint之类的错误,因为restful是基于http协议的,也就是基于URI,所以客户端采用webClient,参考代码如下:

      protected void Page_Load(object sender, EventArgs e)
            {
                GetInfoByID("F00000O593");
            }
            private void GetInfoByID(string id)
            {
                WebClient proxy = new WebClient();
                string serviceURL = string.Empty;
                DataContractJsonSerializer obj;
                if (string.IsNullOrEmpty(id))
                {
                    serviceURL = string.Format("URI/");
                    obj = new DataContractJsonSerializer(typeof(List<>));
                }
                else
                {
                    serviceURL = string.Format("URI/" + id);
                    obj = new DataContractJsonSerializer(typeof(FundClassBasicRecord));
                }
                byte[] data = proxy.DownloadData(serviceURL);
                Stream stream = new MemoryStream(data);
                var result = obj.ReadObject(stream);
                List<InforRecord> list = new List<InforRecord>();
                if (result is InforRecord)
                    list.Add(result as InforRecord);
                else if (result is List<InforRecord>)
                    list = result as List<InforRecord>;
            }
  • 相关阅读:
    php操作zip压缩文件
    php图像处理(thinkphp框架有相对强大的图像处理功能)
    php实现希尔排序(总结)
    PHP glob() 函数详解
    php资源类型变量
    dump var_dump print print_r的区别
    php实现遍历文件目录
    php常用函数
    php全局变量的使用
    php函数按地址传递参数(php引用)
  • 原文地址:https://www.cnblogs.com/cby-love/p/5333760.html
Copyright © 2011-2022 走看看