How can I create a user for ASP.Net/Umbraco SQL Membership from iPhone and WCF?
So I have been struggling for days now, trying to simply create a new user with a WCF Service using Umbraco's Membership Provider. Can someone tell me if I'm out of my mind, if this is impossible to do, or if I'm overlooking something I need to add to my WCF Service to allow this to work. My WCF script is embedded into my website on IIS 7.5 using .NET Framework 4.0.
I can currently return my JSON strings from WCF, such as validation of input. And I will be using this from an iPhone App.
But as soon as everything validates, and I try to run the following lines...
MembershipCreateStatus status;
MembershipUser newUser = Membership.CreateUser(email, pw1, email, "n", "n", false, out status);
if (newUser != null)
{
string newUserGuid = System.Guid.NewGuid().ToString("N");
MemberProfile mp = MemberProfile.GetUserProfile(email);
mp.AuthGuid = newUserGuid;
mp.FirstName = fname;
mp.LastName = lname;
mp.Birthday = bDay;
mp.DisplayRealName = intName;
mp.DisplayBirthday = intBirthday;
mp.Save();
Roles.AddUserToRole(email, "Client");
return @"Valid:User Added";
}else
return @"Error:Invalid:Error Occurred";
}
I get the following error...
The server encountered an error processing the request. The exception message is 'Object reference not set to an instance of an object.'. See server logs for more details. The exception stack trace is:
at umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(String loginName) at umbraco.providers.members.UmbracoMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, MembershipCreateStatus& status) at MyDll.Web.AUsers.RegisterUser(String email, String pw1, String pw2, String fname, String lname, Int32 intName, String birthdate, Int32 intBirthday) at MyDll.Web.get.Users.Register(String email, String p1, String p2, String fname, String lname, String displayname, String birthdate, String displaybirth) at SyncInvokeRegister(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceMod开发者_如何学运维el.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
My Web Config section looks like this...
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="jsonBinding" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyDll.Users">
<endpoint address="/get/Users.svc" behaviorConfiguration="jsonBehavior"
binding="webHttpBinding" bindingConfiguration="jsonBinding"
name="UsersService" contract="MyDll.Web.get.Users" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Any help whatesoever would be GREATLY appreciated. And if I could buy you a beer or 10, I would. Thanks!
In umbraco Member.cs, there is
HttpContext.Current.Trace.Warn("No member with loginname: " + loginName + " Exists");
So you got such error.
In web.config under system.serviceModel add:
<serviceHostingEnvironment aspNetCompatibilityEnabled=”true”/>
on your service class
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
For more information, please see http://msdn.microsoft.com/en-us/library/aa702682.aspx
http://our.umbraco.org/forum/developers/api-questions/18465-Access-Umbraco-Content-from-WCF-Service
精彩评论