簡単なテスト用の Wcf サービスで基本認証を使用すると問題が発生します。例外が発生しています:
要求されたサービス 'http://qld-tgower/test/Service.svc' を有効にできませんでした。詳細については、> サーバーの診断トレース ログを参照してください。
トレース ログには次のように表示されます。
ホスト ('Basic') で構成された認証スキームは、バインディング 'BasicHttpBinding' ('Anonymous') で構成されたものを許可しません。SecurityMode が Transport または TransportCredentialOnly に設定されていることを確認してください。さらに、IIS 管理ツール、アプリケーション構成ファイルの <serviceAuthenticationManager> 要素の ServiceHost.Authentication.AuthenticationSchemes プロパティ、バインディングの ClientCredentialType プロパティを更新することによって、このアプリケーションの認証方式を変更することで解決される場合があります。または、HttpTransportBindingElement の AuthenticationScheme プロパティを調整します。
しかし、基本認証を使用していると表示される間違ったユーザー名とパスワードを使用すると、何が理解できますか?
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);
}
}
ここに欠けているものはありますか?