msdnの推奨に従って、ASP.Net認証サービスを有効にしました。次に、コンソールアプリまたはwinformsアプリを介してサービスを使用しようとしています(ローカルのWCFサービスにサービス参照を追加することにより)。私はカスタム認証とトランスポートセキュリティを行っています(したがって、正常に機能するAuthenticationService.Authenticating
イベントを処理してGlobal.asax
います)。
CookieContainer
認証自体は正常に機能しますが、サービス参照を追加して作成されたプロキシにはプロパティが含まれていません。これは、認証を必要とする後続のサービスにCookieトークンを渡そうとすると明らかに問題になります。
また、次のクライアントコードでは、IsLoggedIn()
falseが返されます。これは、Cookieコンテナが存在しないことに関連していると思います。
ServiceReference1.AuthenticationServiceClient client =
new ServiceReference1.AuthenticationServiceClient();
bool isLoggedIn = client.Login("test", "test", "", true); //returns TRUE
bool check = client.IsLoggedIn(); //returns FALSE
これがサービスの私のweb.configです:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true"
requireSSL = "false"/>
</webServices>
</scripting>
</system.web.extensions>
<system.serviceModel>
<services>
<service name="System.Web.ApplicationServices.AuthenticationService"
behaviorConfiguration="AuthenticationServiceTypeBehaviors">
<endpoint contract="System.Web.ApplicationServices.AuthenticationService"
binding="basicHttpBinding"
bindingConfiguration="userHttps"
bindingNamespace="http://asp.net/ApplicationServices/v200"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="userHttps" allowCookies="true">
<!--<security mode="Transport" />-->
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AuthenticationServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
</configuration>
編集:他に追加する必要があるものがあります。メソッドを呼び出すサービスのフィドラーセッションを実行しました。CookieLogin
が設定され、クライアントに返送されています。しかし、CookieContainerなしで何をすべきでしょうか?