WCF:如何从配置中获取绑定对象 [英] WCF: How to get Binding object from configuration

查看:43
本文介绍了WCF:如何从配置中获取绑定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从web.config或app.config获取绑定对象.

I would like to get Binding object from web.config or app.config.

因此,此代码有效:

wcfTestClient = new TestServiceClient("my_endpoint", Url + "/TestService.svc");

但我想执行以下操作:

Binding binding = DoSomething();
wcfTestClient = new TestServiceClient(binding, Url + "/TestService.svc");

我当然对DoSomething()方法感兴趣.

I am interested in DoSomething() method, of course.

推荐答案

您可以实例化绑定,并从App.config/Web.config中给出绑定配置名称.

You can instantiate a binding giving a binding configuration name from App.config/Web.config.

http://msdn.microsoft.com/en-us/library/ms575163.aspx

使用其配置名称指定的绑定来初始化WSHttpBinding类的新实例.

Initializes a new instance of the WSHttpBinding class with a binding specified by its configuration name.

以下示例显示了如何初始化的新实例带有字符串参数的WSHttpBinding类.

The following example shows how to initialize a new instance of the WSHttpBinding class with a string argument.

// Set the IssuerBinding to a WSHttpBinding loaded from config
b.Security.Message.IssuerBinding = new WSHttpBinding("Issuer");

这篇关于WCF:如何从配置中获取绑定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆