Answered by:
WCF and Custom Profile Provider

Question
-
User1186064815 posted
I have a custom SQL profile provider and I would to access the users profile properties in a WCF web service. I have the profile provider settings added to the web.config and I have successfully implemented a custom membership and role provider within the same WCF web service. When i try to call System.Web.HttpContext.Current.Profile.GetPropertyValue("MyPropertyName").ToString() it returns null because the current user is null. I have <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> in my web.config and [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] on my WCF service.
Wednesday, March 13, 2013 3:24 PM
Answers
-
User1186064815 posted
Here's the answer:
public string GetData(int value)
{
IIdentity currentUser = ServiceSecurityContext.Current.PrimaryIdentity;
if (Roles.IsUserInRole(currentUser.Name, "Developer"))
{
CDIMembershipUser u = (CDIMembershipUser)Membership.GetUser(currentUser.Name);
ProfileBase pb = ProfileBase.Create(currentUser.Name, currentUser.IsAuthenticated);
String accountNumber = pb.GetPropertyValue("AccountNumber").ToString();
return string.Format("Hello {0}. You entered: {1}.", u.FirstName + " " + u.LastName + "(" + accountNumber + ")", value);
}
else
{
return "Access denied";
}
}
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 19, 2013 12:22 PM
All replies
-
User-1000095884 posted
Hi,
I would suggest you take a look at this document to check if you have missed some steps to use the profile provider to connect to the database.
#How to: Build and Run the Profile Provider Example
http://msdn.microsoft.com/en-us/library/8zs47k7y(v=vs.100).aspx
Best Regards.
Friday, March 15, 2013 8:25 AM -
User1186064815 posted
Haixia, I am able to use my custom profile provider in a website. So I am pretty sure the implementaiton is correct. The problem is that I am unable to use the profile provider within a WCF service.
Friday, March 15, 2013 1:09 PM -
User-1662538993 posted
Check this links -
http://channel9.msdn.com/forums/TechOff/416964-Custom-Membership-Providers-in-WCF--Silverlight/
Friday, March 15, 2013 1:57 PM -
User1186064815 posted
Here's the answer:
public string GetData(int value)
{
IIdentity currentUser = ServiceSecurityContext.Current.PrimaryIdentity;
if (Roles.IsUserInRole(currentUser.Name, "Developer"))
{
CDIMembershipUser u = (CDIMembershipUser)Membership.GetUser(currentUser.Name);
ProfileBase pb = ProfileBase.Create(currentUser.Name, currentUser.IsAuthenticated);
String accountNumber = pb.GetPropertyValue("AccountNumber").ToString();
return string.Format("Hello {0}. You entered: {1}.", u.FirstName + " " + u.LastName + "(" + accountNumber + ")", value);
}
else
{
return "Access denied";
}
}
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 19, 2013 12:22 PM