【发布时间】:2015-09-12 17:01:28
【问题描述】:
我经常想在测试期间更改 WCF 服务客户端的主机 URL。在我的配置中,我通常有这样的绑定:
<basicHttpBinding>
<binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="5120000" maxNameTableCharCount="16384"/>
<security mode="Transport">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
在运行时换出地址很容易:
ServiceClient svc = new ServiceClient();
svc.Endpoint.Address = new EndpointAddress("http://wherever");
问题是,如果我将地址从 https 更改为 http,调用该服务会显示它需要 https,因为它正在尝试使用传输安全性。
看来svc.Endpoint的Binding是只读的,只能在构造函数中设置。我可以使用正确的安全模式创建绑定,但随后我丢失了配置文件中配置的所有其他属性值。我不想尝试明确地复制它们。有没有办法使用配置文件的<binding> 创建一个新的 BasicHttpBinding,然后更改它的安全模式,以便我可以使用绑定来实例化 svc?
【问题讨论】:
标签: c# wcf configuration