views:

150

answers:

4

I would like to use Windows Forms with a WCF service and leverage the pre-built authentication of asp.net by using aspNetCompatibilityEnabled = true in the WCF service.

Is there any module or pre-built assemblies that can add ASP.NET functionality to a Windows Forms application? As far as I understand, this functionality isn't built into Windows Forms and can't be leveraged.

+1  A: 

While it is certainly possible host the asp.net runtime in a desktop application, that would involve a bit of plumbing you will need to do manually. In case you want to use the membership provider, you'll also have to handle the certificates.

I would recommend you to either :

  1. host it in IIS or WAS, depending on your system
  2. host it in Cassini, which you could manually start/stop from the command line or programatically
  3. host it in your windows forms application by creating an instance of ServiceHost and opening it manually.
Petar Kabashki
Is there any additiona documentation you can point me to in order to host the aspnet runtime in a desktop application? I believe the runtime provides a way to get some sort of token that you hold onto when you login, so you dont have to pass your username and pw every time to your service. Just like when you log into an aspnet web application or silverlight application.
+2  A: 

I am not aware of anything that's available out of the box, for this scenario.

The whole ASP.NET membership and role system is based on a known SQL Server database called "aspnetdb", which features some tables and stored procedures for the most commonly required functions - so there's really nothing stopping you from building a Winforms based front-end to that underlying database.

I don't know if there's any official documentation on the ASP.NET membership tables and routines - but as far as I recall, they're all fairly straightforward to reengineer and use - so go ahead and build that system of yours!

If you Google or Bing for it, you can even find quite a few articles and blog post from folks who've done that themselves:

marc_s
Thank you very much.
A: 

This is all possible as I've worked on a solution with the scenario that you've described. It's all down to configuration. My recommendation would be to follow this CodePlex Checklist for that scenario. It contains a step by step guide for configuring your application. It shows you how to set up your user store (database), client authentication, setup IIS, security etc.

Tanner
http://www.zamd.net/2009/03/05/FlowingFormsAuthenticationCookieToWCF.aspxI also found this link helpful
A: 

If you do insist on hosting the http runtime in a windows forms appliciation, the easiest way is to get the source code of cassini for .net 3.5 . Really straightforward to use. It is a winforms application already. Cassini is the development server for Visual Studio.

I have personally tested it on a website with membership set on and works perfectly. If you need it to process requests other than from localhost though, you need to change IPAddress.Loopback to IPAddress.Any in Server.cs, as pointed out in the comments.

Petar Kabashki