3

I am new to all the web thing so the question may seem trivial but not to me. The implementation logic is:

ASP.NET MVC 3 -> WCF Service -> SQL Database

Authentication and authorization in ASP.NET MVC3 use custom Membership and Role providers because all the log in details are stored in SQL Database. There is a requirement to implement authorization to WCF service too. That uses the same credentials as ASP.NET MVC 3. I have implemented Username type for WCF security using custom UsernameValidator.

<security mode="TransportWithMessageCredential">
  <transport clientCredentialType="None" />
  <message clientCredentialType="UserName" />
</security>

It works for the first time, when user logs in to the web site because there are credentials. However, after FormsAuthentication.SetAuthCookie on ASP.NET MVC 3, the user name is all I have. As MVC approach consists of variety of controllers, I have to create instance of WCF client on each and every of them. But without credentials it does not make sense.

       [Authorize]
        public class MyController : Controller
        {
            private WebServiceClient ServiceClient = new WebServiceClient();

            public ActionResult Index(string userName)
            {
              var model = ServiceClient.GetDataList();
              return View(model);
            }
        }

The new instance does not use existing session. It creates a new one with blank credentials.

  • Is there a secure way of creating instance of WCF client per session?
  • Or an option of WCF accepting ASP.NET authentication?
  • What is the best way of attaching asp.net authentication to wcf request?
tereško
  • 58,060
  • 25
  • 98
  • 150
Margo
  • 39
  • 1
  • 5
  • Have a look at this post here: http://stackoverflow.com/questions/3460435/asp-net-to-wcf-passthrough-security and even better this post here: http://stackoverflow.com/questions/3451578/wcf-authentication-using-sql-membership-provider – Nope Feb 16 '12 at 13:16
  • Thank you for the links. The first one was very useful. – Margo Feb 17 '12 at 10:41
  • Nice one. Glad you found a solution. – Nope Feb 17 '12 at 13:25

1 Answers1

0

After reading the suggested link it was decided to keep ASP.NET MVC server and WCF service on one machine and use net.pipe endpoint for communication. Thank you.

Community
  • 1
  • 1
Margo
  • 39
  • 1
  • 5