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 ...
随机推荐
- 使用 Python 第三方库 daft 绘制 PGM 中的贝叶斯网络
daft 的官方文档请见 DAFT:BEAUTIFULLY RENDERED PROBABILISTIC GRAPHICAL MODELS. from matplotlib import rc rc( ...
- 详解javascript的深拷贝与浅拷贝
1. 认识深拷贝和浅拷贝 javascript中一般有按值传递和按引用传递两种复制,按值传递的是基本数据类型(Number,String,Boolean,Null,Undefined),一般存放于内存 ...
- 【Educational Codeforces Round 31 B】Japanese Crosswords Strike Back
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 所有数字的和加上n-1,如果为x则唯一,否则不唯一 [代码] #include <bits/stdc++.h> usin ...
- HDU 1874 畅通工程续 SPFA || dijkstra||floyd
http://acm.hdu.edu.cn/showproblem.php?pid=1874 题目大意: 给你一些点,让你求S到T的最短路径. 我只是来练习一下SPFA的 dijkstra+邻接矩阵 ...
- Snail—Hibernate之自写固定组件
Hibernate的存储都是在session中进行的,此session非彼session 以下就是从生成的Hibernate配置文件获得连接数据库,然后再得到session等等 package com ...
- 搭建MHA问题汇总
1,Can't exec "mysqlbinlog": No such file or directory at /usr/share/perl5/vendor_perl/MHA/ ...
- 判断客户端是iPad、安卓还是ios
武穆逸仙 有人心疼时,眼泪才是眼泪,否则只是带着咸味的液体:被人呵护着,撒娇才是撒娇,要不然就是作死. 努力做一个可爱的人,不埋怨谁,不嘲笑谁,也不羡慕谁,阳光下灿烂,风雨中奔跑,做自己的梦,走自己的 ...
- 格式化上下文formatting contexts
原文 简书原文:https://www.jianshu.com/p/20c32c367b63 什么是格式化上下文(formatting contexts) Formatting context是W3C ...
- 浅浅的分析下es6箭头函数
原文链接:http://damobing.com/?p=589 前言 箭头函数作为es6重点的语法内容之一,很多开发者对其爱不释手,当也要注意其可能存在的问题,其正确的使用场景,否则会引起不必要的bu ...
- [AngularFire2] Update multi collections at the same time with FirebaseRef
At some point, you might need to udpate multi collections and those collections should all updated s ...