获取结果中的Rally身份验证问题

时间:2017-02-20 13:46:42

标签: asp.net-mvc asp.net-web-api rally

我正在使用asp.net MVC应用程序并使用Rally Web API进行集成。我想从拉力赛网站获取数据。

登录控制器中的

            RallyRestApi restApi = new RallyRestApi(webServiceVersion: "v2.0");
            dynamic authenticateUser=restApi.Authenticate(usr.UserName, usr.Password, "https://rally1.rallydev.com/", allowSSO: false);
            dynamic objUserName;
            if (authenticateUser.ToString().ToLower() == "authenticated")
            {
                Session["Username"] = usr.UserName;
                Session["Password"] = usr.Password;                   
                FormsAuthentication.SetAuthCookie(usr.UserName, true);
                FormsAuthentication.SetAuthCookie(usr.Password, true);
                objUserName = restApi.GetCurrentUser();
                Session["DisplayName"] = objUserName["DisplayName"];
                return RedirectToAction("Home", "PortfolioItem");
            }

此处身份验证成功。但根据我的研究,如果我们想每次都获取数据,我认为我们需要传递用户身份验证的详细信息,如下所示:

      CreateResult createResult = restApi.Create("defect", toCreate); // need to get with same restApi object or authentication details


      OperationResult updateResult = restApi.Update(createResult.Reference, toUpdate);

      //Get the item
      DynamicJsonObject item = restApi.GetByReference(createResult.Reference);// need to get with same restApi object or authentication details

      //Query for items
      Request request = new Request("defect");
      request.Fetch = new List<string>() { "Name", "Description", "FormattedID" };
      request.Query = new Query("Name", Query.Operator.Equals, "My Defect");
      QueryResult queryResult = restApi.Query(request); // need to get with same restApi object or authentication details

如上所述,如果我们需要获取任何内容,我们需要首先进行身份验证吗?请澄清一下。

1 个答案:

答案 0 :(得分:0)

您需要为您创建的每个RallyRestApi实例进行一次身份验证。一般来说,创建一个,使用它,然后处理它而不是创建它一次然后永远保持在会话中更好。