如何从iPhone和WCF为ASP.Net/Umbraco SQL成员创建用户?

时间:2011-02-24 00:57:55

标签: iphone wcf asp.net-membership umbraco sqlmembershipprovider

所以我一直在苦苦挣扎几天,尝试使用Umbraco的会员提供商简单地创建一个使用WCF服务的新用户。有人可以告诉我,如果我不在乎,如果这是不可能的,或者我忽略了我需要添加到我的WCF服务以允许它工作的东西。我的WCF脚本使用.NET Framework 4.0嵌入到IIS 7.5上的网站中。

我现在可以从WCF返回我的JSON字符串,例如输入验证。我将从iPhone应用程序中使用它。

但是只要一切都有效,我就会尝试运行以下几行......

  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";
  }

我收到以下错误...

  

服务器在处理请求时遇到错误。异常消息是“对象引用未设置为对象的实例。”。请参阅服务器日志以获取更多详异常堆栈跟踪是:

     

在   umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(字符串   loginName)at   umbraco.providers.members.UmbracoMembershipProvider.CreateUser(字符串   username,String password,String   email,String passwordQuestion,String   passwordAnswer,Boolean isApproved,   对象providerUserKey,   MembershipCreateStatus&安培;地位)   System.Web.Security.Membership.CreateUser(字符串   username,String password,String   email,String passwordQuestion,String   passwordAnswer,Boolean isApproved,   对象providerUserKey,   MembershipCreateStatus&安培;地位)   System.Web.Security.Membership.CreateUser(字符串   username,String password,String   email,String passwordQuestion,String   passwordAnswer,Boolean isApproved,   MembershipCreateStatus&安培;地位)   MyDll.Web.AUsers.RegisterUser(字符串   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)   SyncInvokeRegister(Object,Object [],   对象[])在   System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象   实例,对象[]输入,对象[]&   输出)   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.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&安培;   rpc)at   System.ServiceModel.Dispatcher.MessageRpc.Process(布尔   isOperationContextSet)

My Web Config部分看起来像这样......

<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>

任何帮助都会非常感激。如果我可以给你买一杯啤酒或10支啤酒,我愿意。 谢谢!

1 个答案:

答案 0 :(得分:2)

在umbraco Member.cs中,有

HttpContext.Current.Trace.Warn("No member with loginname: " + loginName + " Exists");

所以你得到了这样的错误。

在system.serviceModel下的web.config中添加:

<serviceHostingEnvironment aspNetCompatibilityEnabled=”true”/>

在您的服务类

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

有关详细信息,请参阅 http://msdn.microsoft.com/en-us/library/aa702682.aspx

http://our.umbraco.org/forum/developers/api-questions/18465-Access-Umbraco-Content-from-WCF-Service