2009-11-04 46 views
0

以下是一些舊的ASMX代碼,我需要轉換爲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 

我的AuthenticationType在WCF設置爲BASIC怎麼辦服務?

回答

2

在服務主機如果您想通過配置做到這一點,你可以做到這一點編程方式使用的wsHttpBinding

WSHttpBinding binding = new WSHttpBinding(); 
binding.Security.Mode = SecurityMode.Transport; 
binding.Security.Transport.ClientCredentialType = 
    HttpClientCredentialType.Basic; 

<?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>