我有一个使用多个WCF服务的Web应用程序。我在各种环境(dev,UAT,production等)中部署我的web应用程序。每个WCF服务的URL对于每个环境都是不同的。我正在使用.NET 3.5和basicHttpBinding
s根据环境更改WCF服务参考URL
Web应用程序使用框架来支持web.config文件中的计算机特定设置。当实例化一个WCF服务客户端的一个实例,我认为这种使用构造函数重载需要的参数创建WCF服务客户端的实例函数:
System.ServiceModel.Channels.Binding binding,
System.ServiceModel.EndpointAddress remoteAddress
本质web.config中的<system.serviceModel><bindings><basicHttpBinding><binding>
配置已被复制在C#代码中。
这种方法效果很好。
但是,我现在必须增强此方法以使用使用X509证书的WCF服务。这意味着我必须复制在C#代码在web.config中进行设置:
<!-- inside the binding section -->
<security mode="Message">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
<behaviors>
<endpointBehaviors>
<behavior name="MyServiceBehaviour">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My"
x509FindType="FindByThumbprint" findValue="1234abcd" />
<serviceCertificate>
<defaultCertificate storeLocation="LocalMachine" storeName="My"
x509FindType="FindByThumbprint" findValue="5678efgh" />
<authentication trustedStoreLocation="LocalMachine"
certificateValidationMode="None" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
我有一些困难,搞清楚如何在编写C#此配置。
两个问题
- 谁能推荐为跨多个环境管理WCF服务参考网址更好的方法?
- 另外,关于如何复制C#中的上述web.config部分,任何建议将受到欢迎
为我的答案增加了一些额外的想法 - 您可以使用命名绑定等方式,以便您可以根据您的环境确定名称,然后从配置文件中加载适当的值。 – 2009-04-28 15:33:28
下面的问题涉及到这个http://stackoverflow.com/questions/798684/programmatically-set-identity-on-wcf-endpoint地址 – 2009-04-30 09:20:32
我意识到你在代码而不是在配置文件中这样做,但为什么不使用配置转换并将环境特定设置放置在适当的配置文件(Web.config.dev,Web.config.Test,Web.config.Release等)中? – camainc 2010-10-28 16:37:05