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>, 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<Book> GetList()
{
return base.Channel.GetList();
}
}
}
創(chuàng)建類BookServiceProxyusing 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<Book> list = new List<Book>();
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<Book> 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;
}
}
}
}
文章標(biāo)題:WCF客戶端代理-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://m.newbst.com/article4/dcepoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站設(shè)計(jì)公司、軟件開發(fā)、標(biāo)簽優(yōu)化、Google、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容