Frage

I am using WCF service, which have two endpoint WsHttpBinding and NetTcpBinding and the service is using Forms Authentication. Service is hosted on IIS 7.

This works perfectly with WsHttpBinding, but fails for NetTcpBinding.

It fails on below statement:

FormsAuthentication.SetAuthCookie("COOKIENAME", false);

And the exception is :

Object reference not set to an instance of an object.

Please share your ideas on this.

War es hilfreich?

Lösung

Forms Authentication requires cookies/session which is not supported by protocol itself. So, Forms authentication can not implemented on NetTcpBinding of WCF service.

Andere Tipps

Option 1:

As an Alternative:

  • Add references to System.IdentityModel & System.IdentityModel.Selectors as well as the WCF assemblies.
  • Set the security mode to Message on your binding
  • Set the Message.ClientCredentialType to MessageCredentialType.UserName
  • Create a type derived from UserNamePasswordValidator and implement the only method. You should throw a SecurityTokenException if the user name / password pair does not validate.

On your service host instance's Credentials property, set:

  • UserNameAuthentication.UserNamePasswordValidationMode to UserNamePasswordValidationMode.Custom
  • UserNameAuthentication.CustomUserNamePasswordValidator to a new instance of your UserNamePasswordValidator-derived class.
  • Set a service certificate with ServiceCertificate.SetCertificate()

As for the client-side credentials dialog, you can either make one yourself and on your proxy set proxy.ClientCredentials.UserName.UserName & proxy.ClientCredentials.UserName.Password before you open the proxy / use it the first time. Or you can check out how you can implement the System.ServiceModel.Dispatcher.IInteractiveChannelInitializer to create your own interactive initialization UI.

Option 2:

Another Alternative this sounds more like what you want to do ..Passing FormsAuthentication cookie to a WCF service

Why did I provide an answer to an old post - because someone might be looking for an answer. Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top