WCF客户端C#代码 配置config文件
不多说了,直接上代码吧。。。。
服务端Web.config文件中bindings配置
<bindings>
<wsHttpBinding>
<binding name="httpconf" closeTimeout="10:10:10"
openTimeout="10:10:10" receiveTimeout="10:10:10" sendTimeout="10:10:10"
allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
<reliableSession ordered="true" inactivityTimeout="00:20:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
服务端Web.config文件中behavior配置
<behavior name="Card_WcfService.WCF.CardInfoServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceTimeouts transactionTimeout="00:10:00" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647" />
</behavior>
服务端Web.config文件中service配置
<service behaviorConfiguration="Card_WcfService.WCF.CardInfoServiceBehavior"
name="Card_WcfService.WCF.CardInfoService">
<endpoint address="" binding="wsHttpBinding" contract="Card_SystemAPI.ICardInfoService" bindingConfiguration="httpconf">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
下面才是我想要的东西,弄这个花了我半天时间
客户端代码注册配置文件
public class ClientFactory<TClient> : IDisposable
{
static EndpointAddress serviceAddress;
static WSHttpBinding binding;
ChannelFactory<TClient> factory;
TClient proxy;
OperationContextScope scope;
public TClient CreateClient()
{
factory = new ChannelFactory<TClient>(binding, serviceAddress);
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{ DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>()
as DataContractSerializerOperationBehavior; if (dataContractBehavior != null)
{ dataContractBehavior.MaxItemsInObjectGraph = 2147483647; } }
proxy = factory.CreateChannel();
((IClientChannel)proxy).Faulted += new EventHandler(a_Faulted);
scope = new OperationContextScope(((IClientChannel)proxy));
var curId = CacheStrategy.CurUser == null ?Guid.Empty : CacheStrategy.CurUser.AutoID;
MessageHeader<Guid> mhg = new MessageHeader<Guid>(curId);
MessageHeader untyped = mhg.GetUntypedHeader("token", "ns");
OperationContext.Current.OutgoingMessageHeaders.Add(untyped);
return proxy;
}
void a_Faulted(object sender, EventArgs e)
{
//todo:此处得不到异常的内容
}
public void Dispose()
{
try
{
scope.Dispose();
((IClientChannel)proxy).Close();
factory.Close();
}
catch
{
}
}
static ClientFactory()
{
var surl = ConfigurationManager.AppSettings["ServiceURL"];
var iname = typeof(TClient).FullName.Substring("Card_SystemAPI.I".Length);
var sname = string.Format("{0}.svc", iname);
var url = Path.Combine(surl, sname);
serviceAddress = new EndpointAddress(url);
binding = new WSHttpBinding();
binding.CloseTimeout = new TimeSpan(10, 10, 10);
binding.OpenTimeout = new TimeSpan(10, 10, 10);
binding.SendTimeout = new TimeSpan(10, 10, 10);
binding.ReceiveTimeout = new TimeSpan(10, 10, 10);
binding.MaxReceivedMessageSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
binding.AllowCookies = true;
}
}
QQ群号: 242251580 身份认证:.NET技术讨论
如有转载,请保留原有地址:http://www.cnblogs.com/hank-hu/p/4663568.html
WCF客户端C#代码 配置config文件的更多相关文章
- PHP 后台程序配置config文件,及form表单上传文件
一,配置config文件 1获取config.php文件数组, 2获取form 表单提交的值 3保存更新config.php文件,代码如下: $color=$_POST['color']; $back ...
- WCF客户端简单动态配置服务地址
本来想实现WCF服务无论放到哪个机器上,我的客户端都不需要重新编译,只需要配置一个服务的地址即可.各种百度找到了很多解决方案.但都比较繁琐,(只要因为个人小菜看不懂太多的代码)我对WCF内部机制还不了 ...
- winform客户端程序实时读写app.config文件
新接到需求,wcf客户端程序运行时,能实时修改程序的打印机名称: 使用XmlHelper读写 winform.exe.config文件修改后始终,不能实时读取出来,查询博客园,原来已有大神解释了: 获 ...
- git配置config文件
1.Git有一个工具被称为git config,它允许你获取和设置变量:这些变量可以控制Git的外观和操作的各个方面.这些变量以等级的不同可以被存储在三个不同的位置: (1) /etc/gitconf ...
- Linux内核配置.config文件
在命令行中,进入顶层内核目录,并输入命令make menuconfig,就可以启动一个基于菜单的内核配置编辑器.从这里开始,你可以访问每个可用的配置参数,并生成一个定制的内核配置. 当你退出配置编辑器 ...
- silverlight 生成图表 WCF 解析XML代码.svc.cs 文件
silverlight 调用wcf 文件代码 private ListItem AnalyzeXML(string XMLCode, string Reportdate, string ChartNa ...
- 【IIS】IIS6.1配置 *.config 文件 的MIME类型用于升级程序
参考:http://blog.csdn.net 1. 2. 请求筛选中允许config文件下载, 3. 添加.config到 MIME类型. 3.注意:筛选项.
- HDFS的Java客户端操作代码(HDFS删除文件或目录)
1.HDFS删除文件或目录 package Hdfs; import java.io.IOException; import java.net.URI; import org.apache.hadoo ...
- WCF客户端关闭代码
Close不一定会成功,所以需要Abort. ChannelFactory channel = new ChannelFactory<IService1>("bindingN ...
随机推荐
- 基于AndFix的热修复 成功后简单的总结总结错失
首先了解热修复是什么东西?? 就我自己简单的理解:就是不须要又一次打包 公布到市场 然后再让用户又一次下载就能够把一些小bug和需求通过补丁的形式进行改动. 然后如今的热修复方式有大致的三种: 1.d ...
- Visual studio编译器窗体重置
针对vs2003: 第一种方法 在"工具"->"选项"对话框里面: 在"选项"以下的"常规"有个"重置 ...
- 百度ueditor vue项目应用 -- 图片上传源码修改
本文目的有两个,一.废掉单图上传,二.改造多图上传 大家都知道百度ueditor不是针对vue项目开发的,官方文档提供的源码包里有需要后端配置的接口,but到vue项目就不太好办了,网上有些文章也介绍 ...
- angular4开发过程中遇到的问题和知识点记录
1. angular2中的属性有什么区别,为什么会报错呢? 元素上有两种属性:property和attribute,attribute是通过getAttribute()和setAttribute()方 ...
- (转)Vim练级攻略
(转)Vim练级攻略 原文链接:http://coolshell.cn/articles/5426.html vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆 ...
- hdu 5078 Osu!(鞍山现场赛)
Osu! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Sub ...
- UIActionSheet上加入UIPickerView iOS8替换方案
此套替换方案採用"UIView+动画"方式实现(将UIActionSheet替换为UIView) 界面层级例如以下: 第一层:view(这一层充满整个屏幕,初始化时颜色为透明.us ...
- php 获取根目录
在网站根目录的index.php文件里 define('BASE_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/ ...
- Springmvc+Shiro实战
原文链接:http://blog.csdn.net/qq_37936542/article/details/79010449 springmvc+shiro实现系统粗细粒度的权限管理步骤: 1:表格设 ...
- ajax跳转到新的jsp页面(局部刷新)
ajax可以实现局部刷新页面,即在不刷新整个页面的情况下更新页面的局部信息. 项目中遇到一个问题:在用户列表也,当点击某个按钮时需要去查询用户的信息,查询成功跳转到用户详情界面:查询失败,则在原页面弹 ...