创新互联建站服务项目包括泗洪网站建设、泗洪网站制作、泗洪网页制作以及泗洪网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,泗洪网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到泗洪省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!- 创建类库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();
}
}
}
创建类BookServiceProxy
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://bzwzjz.com/article/dcepoe.html