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>;
            }
  • 相关阅读:
    给一个二维数组随机赋值
    sql server use WAITFOR DELAY to wait some milliseconds
    sql server print time with milliseconds
    UE4 LeapMotion 获取手掌朝向
    Unity打包Android出现Failed to find Build Tools revision
    UE4中Yaw,Roll,Pitch分别对应什么轴?
    Unity 遍历场景所有物体(包括隐藏及被禁用的物体)
    C#-Linq扩展方法DistinctBy
    Unity编辑器扩展--Scene Manager
    Unity查找功能编辑器扩展Searcher
  • 原文地址:https://www.cnblogs.com/cby-love/p/5333760.html
Copyright © 2011-2022 走看看