私は認証を機能させようとしているテストWCFアプリケーションを作成しましたが、単にメソッドを実行してログイン/認証を要求しません。私がすることが出来るのですWCF認証で資格情報が要求されない
public class Authorization : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (null == userName || null == password)
{
throw new ArgumentNullException();
}
if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
{
// This throws an informative fault to the client.
throw new FaultException("Unknown Username or Incorrect Password");
// When you do not want to throw an infomative fault to the client,
// throw the following exception.
// throw new SecurityTokenException("Unknown Username or Incorrect Password");
}
}
}
マイService.svc.csクラス
public string Hello(string message)
{
return "You typed: " + message;
}
:
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyAPI.Authorization, App_Code" />
</serviceCredentials>
マイ承認クラス:以下は私のWCFのアプリで私のweb.configファイル内のコードスニペットです認証を必要とするか、クラスの上にこのメソッドの上にいくつかの属性を入れてください。
私は、その後のテストコンソールアプリケーションを作成して、ここにコードがある:認証を求めず:
public static Test.Service1Client client = new Test.Service1Client();
static void Main(string[] args)
{
Console.WriteLine(client.Hello("hello"));
Console.ReadLine();
}
これだけで「こんにちはあなたが入力した」を出力します。ここに私はapp.configの抜粋です:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://MyServer/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="Test.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
私がやっによってclient.Hello("hello")
を呼び出す前に、ログイン資格情報を設定する必要が期待される:
client.ClientCredentials.UserName.UserName = "test1";
client.ClientCredentials.UserName.Password = "1tset";
しかし、明らかではない
を編集
が<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyAPI.Authorization, App_Code" />
</serviceCredentials>
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
通常、ブラウザなどのクライアントは、資格情報の入力を要求します。あなたのテストコンソールアプリケーションは、そのようにコード化していないので、プロンプトを表示しません。資格情報を提供していない場合、そのサービスコールは失敗しているはずです。サーバ設定のBinding1バインディングでサービスをバインドしているかどうか確認してください。 – VinayC
@VinayC - それはどこで確認できますか?私の編集を参照してください、それは私のサービスから私のweb.configファイル全体を含んでいます – CallumVass