我幾乎沒有嘗試爲我的WCF(發佈在IIS 8.5)上設置BasicAuthentification。但我總是得到這些錯誤之一:WCF與BasicAuthentification問題
http request was forbidden with client authentication scheme 'basic'. Got following authentificationheader "Digest qop="auth",algorithm=MD5-sess,nonce="someMD5stuff",charset=utf-8,realm="Digest",Negotiate,NTLM,Basic realm="localhost"" from the server.
或
The HTTP request was forbidden with client authentication scheme 'Basic'. Got authentificationheader "Basic realm="localhost"" from server.
我的web.config文件服務器端(在WCF):
<system.serviceModel>
<services>
<service name="WCF_for_APP.Service1">
<endpoint
address=""
binding="basicHttpBinding"
contract="WCF_for_APP.Service"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IPersonService" />
<binding>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm=""/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://somewhere/customerService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPersonService"
contract="PersonService.IPersonService" name="BasicHttpBinding_IPersonStateService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceAuthenticationManager authenticationSchemes="Basic"></serviceAuthenticationManager>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="CustomerValidator.SecureBindingUsernamePasswordValidator, CustomerValidator" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.servicemodel>
我試過它設置一個名稱綁定配置等,但它並沒有改變一件事情。
我試着通過的ChannelFactory客戶方訪問我的WCF的ASP應用:
EndpointAddress endpointAddress = new EndpointAddress(endpointadress);
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.ReaderQuotas.MaxBytesPerRead = Int16.MaxValue;
basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
ChannelFactory<Service> channelFactory = null;
Service client = null;
channelFactory = new ChannelFactory<Service>(basicHttpBinding, endpointAddress);
channelFactory.Credentials.UserName.UserName = ConfigurationManager.AppSettings["wcfUser"].ToString();
channelFactory.Credentials.UserName.Password = ConfigurationManager.AppSettings["wcfPW"].ToString();
try
{
client = channelFactory.CreateChannel();
string a = client.SendMail();
}
catch(Exception e)
{
Response.Write(e.Message);
}
在IIS基本身份驗證被激活。我真的不想切換到HTTPS和證書,因爲我只需要這個basicauthent來實現內部安全。我甚至無法使用visual studio wcf testclient啓動WCF,但是沒有身份驗證設置,一切正常。 WCF和ASP都發布在我的本地IIS上。
有什麼建議是什麼問題?我是否必須使用相同憑據將用戶添加到本地系統?
** 編輯 **
我想我知道的問題!在我的WCF中,我打電話給另一個WCF(來自客戶),並且這個與我的安全設置相結合正在製造麻煩。那麼我如何解決這個問題?我的WCF服務器端配置和客戶端WCF客戶端配置在一個web.config? (客戶WCF也通過ChannelFactory調用)因爲如果我命名綁定配置它不會改變一件事(見上面的代碼)。
通過ChannelFactory進行客戶WCF調用的代碼看起來像上面的代碼。 這可能是問題嗎? 2 WCF - 一個服務器端和一個呼叫?
不要在沒有https的情況下使用BASIC。使用嗅探器將密碼從電線上拉出是微不足道的。不要認爲內部意味着「安全」。 – Crowcoder
@Crowcoder - 我真的不在乎外部人能否看到一些東西。沒有親密的轉移正在進行。只是爲了確保每位員工的內部安全,只要他們錯誤地擊中了WCF的網站。 –
@DaveStockinger您是否嘗試在客戶端添加領域到證書? – mkysoft