【发布时间】:2010-11-19 16:25:01
【问题描述】:
我编写了一个以编程方式配置的简单 WCF Web 服务。它公开了三个端点,它们将不同的绑定绑定到同一个合约:
- WebHttpBinding
- WebHttpRelayBinding(通过 Microsoft azure)
- myBinding(在附加 DLL 中自制绑定)
目前配置代码非常简单:
WebServiceHost host = new WebServiceHost(
typeof(MyService), new Uri("http://localhost:80/"));
host.AddServiceEndpoint(typeof(MyService), new WebHttpBinding(), "");
ServiceEndpoint sbEndpoint = host.AddServiceEndpoint(
typeof(MyService), new WebHttpRelayBinding(), "http://azureURL");
TransportClientEndpointBehavior sbBehavior =
new TransportClientEndpointBehavior();
sbBehavior.CredentialType = TransportClientCredentialType.UserNamePassword;
sbBehavior.Credentials.UserName.UserName = "azureUserName";
sbBehavior.Credentials.UserName.Password = "azurePassword";
sbEndpoint.Behaviors.Add(sbBehavior);
host.AddServiceEndpoint(typeof(MyService), new MyBinding(), "http://someURL");
host.Open();
现在我想将此配置导出到配置文件中,因为我希望能够更改它而无需重新编译。
此时我的问题是:
- 在哪里可以找到有价值的信息来实现我的目标?大多数网站只谈论 SOAP 绑定 - 没有提及如何包含非标准绑定。
- 我是否必须更改 MyBinding 才能通过 app.config 接受配置,或者 ServiceModel 在配置正常时是否像我的编程方法一样调用它?
【问题讨论】:
标签: wcf web-services configuration app-config