using System.ServiceModel;
namespace Falcon.SugarApi.WebService
{
///
/// WebService客户端
///
public static class WebServiceClient
{
///
/// 创建一个符合协议的WebService客户端
///
/// 协议
/// 服务端地址
/// 创建器
/// 实例化的协议通信客户端
///
public static T CreateWebServiceClient(string url,Action? builder = null) {
url=url??throw new ArgumentNullException("url must is not null.");
var bind = new BasicHttpBinding {
MaxBufferSize=int.MaxValue,
ReaderQuotas=System.Xml.XmlDictionaryReaderQuotas.Max,
MaxReceivedMessageSize=int.MaxValue,
AllowCookies=true,
};
var option = new WebServiceClientOption { Address=url,Binding=bind };
builder?.Invoke(option);
return (new ChannelFactory(option.Binding,new EndpointAddress(option.Address))).CreateChannel();
}
}
}