zoukankan      html  css  js  c++  java
  • wcf第4步之原生调用简单封装

     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();
  • 相关阅读:
    Spring基于纯注解的声明式事务控制
    Spring基于XML的声明式事务控制
    2.Jersey
    1.解读REST和JAX-RS
    getHibernateTemplate和getSession 区别, this.getHibernateTemplate().getSessionFactory().getCurrentSession()和OpenSession区别
    eclipse安装maven报错
    MyEclipse10 + tomcat8 64位
    理解MVC
    java编程规范
    c3p0详细配置
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5996226.html
Copyright © 2011-2022 走看看