首页 > 代码库 > wcf第4步之原生调用简单封装
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步之原生调用简单封装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。