[转]使用代码去描述WCF配置文件
在应用程序部署的时候,WCF客户端因为服务器地址的变化,需要修改程序配置文件的地址URL,手动修改很不方便,还会造成错误,所以尽量把描述WCF配置文件的配置使用代码方式进行描述,通过在软件中输入服务器IP地址的方式,动态修改访问的URL,这样比较方便,也不会出错,导致程序运行异常。
下面我将一个WCF部署文件采用代码方式描述:
WCF客户端的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMainService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8888/DataCenter.Factory/MainService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMainService"
contract="IMainService" name="WSHttpBinding_IMainService">
<identity>
<servicePrincipalName value="host/WIN-QFIKKT28EHC" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
编程中使用代码描述上述文件:在这里客户端引用的WCF服务命名空间定义为DataCenterFatoryC,客户端访问对象为 DataCenterFatoryC.MainServiceClient MainServiceClient1;
using System.ServiceModel; WSHttpBinding Bindins; DataCenterFatoryC.MainServiceClient MainServiceClient1; private void MainForm_Load(object sender, EventArgs e)
{
Bindins = new WSHttpBinding();//设置绑定
Bindins.CloseTimeout = TimeSpan.Parse("00:01:00");
Bindins.OpenTimeout = TimeSpan.Parse("00:01:00");
Bindins.ReceiveTimeout = TimeSpan.Parse("00:10:00");
Bindins.SendTimeout = TimeSpan.Parse("00:01:00");
Bindins.BypassProxyOnLocal = false;
Bindins.TransactionFlow = false;
Bindins.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
Bindins.MaxBufferPoolSize = ;
Bindins.MaxReceivedMessageSize = ;
Bindins.MessageEncoding = WSMessageEncoding.Text;
Bindins.TextEncoding = Encoding.UTF8;
Bindins.UseDefaultWebProxy = true;
Bindins.ReaderQuotas.MaxDepth = ;
Bindins.ReaderQuotas.MaxStringContentLength = ;
Bindins.ReaderQuotas.MaxArrayLength = ;
Bindins.ReaderQuotas.MaxBytesPerRead = ;
Bindins.ReaderQuotas.MaxNameTableCharCount = ;
Bindins.ReliableSession.Ordered = true;
Bindins.ReliableSession.InactivityTimeout = TimeSpan.Parse("00:10:00");
Bindins.ReliableSession.Enabled = false;
Bindins.Security.Mode = SecurityMode.Message;
Bindins.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
Bindins.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
Bindins.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
Bindins.Security.Message.NegotiateServiceCredential = true;
Bindins.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
Bindins.Security.Message.EstablishSecurityContext = true; string address = "http://localhost:8888/DataCenter.Factory/MainService/";//服务终结点的URL
MainServiceClient1 = new DataCenterFatoryC.MainServiceClient(Bindins, new EndpointAddress(address));
MainServiceClient1.Open();
}
通过对Bindins的参数设置,能有效的描述访问过程的一些问题,比如上传下载大文件,大数据表都依赖重要参数的设置,否则运行中会有异常错误发生,这是我们应该注意的。
[转]使用代码去描述WCF配置文件的更多相关文章
- WCF 配置文件(三)
配置文件概述 WCF服务配置是WCF服务编程的主要部分.WCF作为分布式开发的基础框架,在定义服务以及定义消费服务的客户端时,都使用了配置文件的方法.虽然WCF也提供硬编程的方式,通过在代码中直接设置 ...
- 30行代码搞定WCF并发性能测试
[以下只是个人观点,欢迎交流] 30行代码搞定WCF并发性能 轻量级测试. 1. 调用并发测试接口 static void Main() { List< ...
- 数据段描述符和代码段描述符(二)——《x86汇编语言:从实模式到保护模式》读书笔记11
这篇博文,我们编写一个C语言的小程序,来解析数据段或者代码段描述符的各个字段.这样我们阅读原书的代码就会方便一点,只要运行这个小程序,就可以明白程序中定义的数据段或者代码段的描述符了. 这段代码,我用 ...
- 数据段描述符和代码段描述符(一)——《x86汇编语言:从实模式到保护模式》读书笔记10
一.段描述符的分类 在上一篇博文中已经说过,为了使用段,我们必须要创建段描述符.80X86中有各种各样的段描述符,下图展示了它们的分类. 看了上图,你也许会说:天啊,怎么这么多段描述符啊!我可怎么记住 ...
- 在Maven项目中添加代码目录下的配置文件
问题 Maven 是约定大于配置的一种工具, 通常约定在 src/main/resources 目录下放配置文件, 当我们想要在 src/main/java 代码目录下放置配置文件用来测试, Mave ...
- 通过纯代码方式发布WCF服务
网络上搜索WCF服务,一般是寄宿在IIS,通过WebConfig方式配服务地址,接口类型等信息,但是对于我这样的懒人,目前项目在开发阶段,实在不愿意每次添加新服务就更新配置文件,于是使用了反射来加载服 ...
- WCF配置文件与文件下载之坎坷路
题外话:本以为我会WCF了,精通WCF了,毕竟刚做过一个WCF的项目,不就是写写契约接口,然后实现接口,改下配置.最后用控制台或者服务发布一下,不就能用了.不就是简单ABC吗?不是So Easy吗?做 ...
- WCF配置文件详解
今天来看看WCF的配置方法. 上图整理了服务配置过程中所用到的基本的元素,大致的步骤主要是首先要在调用服务的程序集中添加服务的一个引用,然后添加一个service并指定服务的名称.终结点,如果添加了b ...
- WCF配置文件
因为要上传较大的图片,WCF传递数组的默认的最大数组16KB就不够了.以下讲解配置内容. 服务端配置 这里一个WCF项目中有1个服务,配置文件如下(位于system.serviceModel标签中): ...
随机推荐
- [Swift通天遁地]三、手势与图表-(11)制作雷达图表更加形象表示各个维度的情况
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- python自动化测试学习笔记-2-字典、元组、字符串方法
一.字典 Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组等其他容器模型. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割, ...
- JAVA小记(一)
java中向上转型.向下转型.内部类中所需注意的问题: 向上转型与向下转型: 举个例子:有2个类,Father是父类,Son类继承自Father. Father f1 = new Son(); / ...
- 349 Intersection of Two Arrays 两个数组的交集
给定两个数组,写一个函数来计算它们的交集.例子: 给定 num1= [1, 2, 2, 1], nums2 = [2, 2], 返回 [2].提示: 每个在结果中的元素必定是唯一的. 我们 ...
- 胖ap和瘦ap的区别
一,什么是AP,胖瘦AP如何区分? 先说说AP的概念.AP是Access Point的简称,即无线接入点,其作用是把局域网里通过双绞线传输的有线信号(即电信号)经过编译,转换成无线电信号传 ...
- DataFrame编程模型初谈与Spark SQL
Spark SQL在Spark内核基础上提供了对结构化数据的处理,在Spark1.3版本中,Spark SQL不仅可以作为分布式的SQL查询引擎,还引入了新的DataFrame编程模型. 在Spark ...
- CSS——img
img标签初始化:在低版本的ie浏览器会自带边框,所以建议border:0px.
- SQL基本操作——UNION
UNION 操作符:用于合并两个或多个 SELECT 语句的结果集.请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SELECT 语句中的列 ...
- js的replace, 高亮
";console.log(str.replace(/\,/g, "")); //输出 123 ";console.log(str);//输出123 " ...
- Render2
https://blog.csdn.net/wf19930209/article/details/81109388