以下是一些旧的ASMX代码,我需要将其转换为WCF服务代码
Dim cc As New System.Net.CredentialCache
cc.Add(New System.Uri(url), "BASIC", New System.Net.NetworkCredential( _
userName, _
password, _
domain))
这是我的WCF代码:
myServiceInstance.Endpoint.Address = New EndpointAddress(url)
Dim credentials As New System.Net.NetworkCredential(userName, password, domain)
myServiceInstance.ClientCredentials.Windows.ClientCredential = credentials
如何在WCF服务中将AuthenticationType设置为BASIC?
答案 0 :(得分:2)
在服务主机中,您可以使用wsHttpBinding
以编程方式执行此操作WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Basic;
如果你想通过config:
这样做<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<!-- Service Details Here -->
</service>
</services>
</system.serviceModel>
</configuration>