我有一个需要调用的WCF服务。当我通过VS“添加服务引用”,我获得以下客户端配置:如何通过代码禁用WCF的CustomBinding的安全性?
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IMyService">
<binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
maxSessionSize="2048">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binaryMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true"
hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://myserver/Service/MyService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IMyService"
contract="MyService.IMyService" name="CustomBinding_IMyService" />
</client>
</system.serviceModel>
</configuration>
当我使用这个配置调用服务,它的工作原理,所以这项服务是好的。但在我的实际应用程序中,我无法使用app.config,并需要使用代码构建服务客户端。我试图做一个简单的翻译:
var binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
var httpTransport = new HttpsTransportBindingElement()
{
Realm = "", ManualAddressing = false,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
TransferMode = TransferMode.Buffered,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue, AllowCookies = false,
AuthenticationScheme = AuthenticationSchemes.Anonymous,
UnsafeConnectionNtlmAuthentication = false
};
var customBinding = new CustomBinding(binaryMessageEncoding, httpTransport);
var myServiceClient = new MyServiceClient(customBinding,
new EndpointAddress(
"http://myserver/Service/MyService.svc"));
但是,当我拨打服务,我得到ArgumentException
,说"The provided URI scheme 'http' is invalid; expected 'https'."
,所以我建立某种原因认为它是安全的结合。所以,现在我们回到原来的问题 - 我如何禁用代码中的CustomBinding
安全?我知道在配置中它是一个简单的<security mode="none"/>
,但我不能使用该配置,并出于某种原因无法找到相应的API。
谢谢! (我怎么能错过它自己?...... Jeez。) – user8032 2010-07-13 14:41:50