码迷,mamicode.com
首页 > 其他好文 > 详细

wcf第4步之原生调用简单封装

时间:2016-10-25 13:47:32      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:dos   封装   iclient   encoding   stc   art   test   ret   partial   

 public interface IDemoServiceChannel :  IDemoService, System.ServiceModel.IClientChannel {
    }
    
 
   
    public partial class DemoServiceClient : System.ServiceModel.ClientBase<IDemoService>, IDemoService {
        
        public DemoServiceClient() {
        }
        
        public DemoServiceClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public DemoServiceClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public DemoServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public DemoServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }
        
        public SomeResp DoSomething(SomeReq request) {
            return base.Channel.DoSomething(request);
        }
    }

 

配置文件添加

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IDemoService" sendTimeout="00:05:00" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://dev.xxx.io/Demo/DemoService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDemoService"
          contract="RestClientTest.IDemoService" name="BasicHttpBinding_IDemoService" />
    </client>
  </system.serviceModel>
</configuration>

 

调用代码更加简单

IDemoService demoService = new DemoServiceClient();
            var r1 = demoService.DoSomething(new SomeReq() { Date = DateTime.Now, DateUTC = DateTimeOffset.Now });
            Console.WriteLine(r1.ResultDate);
            Console.Read();

 

wcf第4步之原生调用简单封装

标签:dos   封装   iclient   encoding   stc   art   test   ret   partial   

原文地址:http://www.cnblogs.com/zhshlimi/p/5996226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!