在簡單的測試Wcf服務中使用基本身份驗證遇到一些麻煩。我收到一個例外:Wcf基本身份驗證
無法激活請求的服務'http://qld-tgower/test/Service.svc'。請參閱>服務器的診斷跟蹤日誌以獲取更多信息。
而在跟蹤日誌它顯示:
主機(「基本」)上配置的身份驗證方案不允許那些綁定「basicHttpBinding的」(「匿名」)進行配置。請確保SecurityMode設置爲Transport或TransportCredentialOnly。此外,可以通過更改此應用程序的身份驗證方案,通過IIS管理工具,通過ServiceHost.Authentication.AuthenticationSchemes屬性,<serviceAuthenticationManager>元素上的應用程序配置文件,通過更新綁定上的ClientCredentialType屬性,或者通過調整HttpTransportBindingElement上的AuthenticationScheme屬性。
但當我我們不正確的用戶名和密碼,它使用基本身份驗證說它IS什麼我不明白呢?
該HTTP請求未經授權,客戶端身份驗證方案爲「基本」。從服務器收到的驗證頭是'Basic realm =「qld-tgower」'。
這是我的web.config細節
<system.serviceModel>
<services>
<service name="WcfService"
behaviorConfiguration="Behavior">
<endpoint address="http://QLD-TGOWER/test/Service.svc"
binding="basicHttpBinding"
bindingConfiguration="httpBinding"
contract="IService" />
</service>
</services>
<diagnostics>
<endToEndTracing activityTracing="false" messageFlowTracing="true" propagateActivity="true"></endToEndTracing>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="Basic">
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
,這是我的App.config
<system.serviceModel>
<diagnostics>
<endToEndTracing activityTracing="true" />
<messageLogging logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="Basic"></transport>
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://QLD-TGOWER/test/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
我的測試應用程序
private static void Main(string[] args)
{
var proxy = new ServiceClient("BasicHttpBinding_IService");
var clientCredentials = proxy.ClientCredentials;
clientCredentials.UserName.UserName = "username";
clientCredentials.UserName.Password = "password";
var res = proxy.GetData(1);
Console.WriteLine(res);
Console.WriteLine("Done");
Console.ReadKey(true);
}
我的服務
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
有沒有,我很想念這裏的東西嗎?
謝謝,這已經修復了認證錯誤,但是現在該服務進入了故障狀態。跟蹤日誌中沒有任何內容可以說明原因。 – TheRealTy