关于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>;
        }

 

转载于:https://www.cnblogs.com/cby-love/p/5333760.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值