资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

WCF客户端代理-创新互联

    创新互联建站服务项目包括泗洪网站建设、泗洪网站制作、泗洪网页制作以及泗洪网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,泗洪网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到泗洪省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
  • 创建类库WCFServiceProxy
  • 添加System.ServiceModel、WCFService(见上篇文章)引用
  • 创建类:BookServiceClient
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;
using WCFService;
using WCFService.Models;

namespace WCFServiceProxy
{
public class BookServiceClient : ClientBase, IBookService
    {
public BookServiceClient() : base() { }
public BookServiceClient(string endpointConfigurationName) : base(endpointConfigurationName) { }
public BookServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { }
public BookServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { }
public BookServiceClient(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress) { }
public bool Add(string name, double price)
        {
return base.Channel.Add(name, price);
        }

public List GetList()
        {
return base.Channel.GetList();
        }
    }
}
创建类BookServiceProxyWCF客户端代理
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using WCFService.Models;

namespace WCFServiceProxy
{
public static class BookServiceProxy
    {
private static string _clientEndpointName = "bookInfo";
static List list = new List();
public static bool Add(string name, double price)
        {
            BookServiceClient client= null;
try
            {
                client= new BookServiceClient(_clientEndpointName);
                client.Add(name, price);
                client.Close();
return true;
            }
catch (Exception ex)
            {
if (client != null && client.State != CommunicationState.Closed)
                {
                    client.Abort();
                    client= null;
                }
return false;
            }
finally
            {
                client= null;
            }
        }

public static List GetList()
        {
            BookServiceClient client= null;
try
            {
                client= new BookServiceClient(_clientEndpointName);
                list= client.GetList();
                client.Close();
return list;
            }
catch (Exception ex)
            {
if (client != null && client.State != CommunicationState.Closed)
                {
                    client.Abort();
                    client= null;
                }
return null;
            }
finally
            {
                client= null;
            }
        }
    }
}

名称栏目:WCF客户端代理-创新互联
分享地址:http://cdkjz.cn/article/dcepoe.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220