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

Posted zslm___

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();

 

以上是关于wcf第4步之原生调用简单封装的主要内容,如果未能解决你的问题,请参考以下文章

原生js封装轮播图

WCF安全性认证:SoapHeader使用HTTP Request调用

使用原生ajax及其简单封装

原生JS简单封装JSONP跨域获取数据

C# 进程通信-命名管道

JavaScript 第4天学习规划丨函数