将服务从ASMX更新到WCF服务问题!

时间:2009-11-04 17:13:20

标签: wcf

以下是一些旧的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?

1 个答案:

答案 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>