0

有没有办法获得结果UserGroup.GetUserInfo但不必指定我要查询的用户,例如 with UserGroup.GetRolesAndPermissionsForCurrentUser

特别是,我正在尝试获取用户 ID(以便我可以判断文档是否已签出给当前登录的用户)。不幸的是,我使用智能卡来提供凭据——没有为实际的文档库输入用户名或密码——所以我不能使用域\用户名GetUserInfo,这就是我对非智能卡使用的方法。

此外,我在 iOS 上,所以我真的没有任何好的 SharePoint API 可以使用——所有东西都需要通过 2007/2010 SOAP WebService API 提供

谢谢!

4

1 回答 1

1

您应该可以使用UserGroup.GetCurrentUserInfo. Sharepoint SOAP 文档可以在这里找到http://msdn.microsoft.com/en-us/library/websvcusergroup.usergroup.getcurrentuserinfo(v=office.14).aspx

如果您有权访问 Sharepoint 实例,则可以在此处检查 SOAP 信封和响应:htttp://your.sharepointserver.com/_vti_bin/usergroup.asmx?op=GetCurrentUserInfo(请勿在应用程序的实际请求中使用此 URL )。

下面是一个基于 AFNetworking 和子类 AFHTTPClient 的示例实现。

// Get user info for currently signed in user
- (void)currentUserInfoWithSuccessBlock:(void(^)(SharepointCurrentUserResponse *response))successBlock
                              failBlock:(void(^)(NSError *error))failBlock {

  NSMutableURLRequest *request = [self requestWithMethod:@"POST"
                                                    path:@"_vti_bin/UserGroup.asmx"
                                              parameters:nil];

  NSString *soapEnvelope =
    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
    @"<soap:Body>"
    @"<GetCurrentUserInfo xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\" />"
    @"</soap:Body>"
    @"</soap:Envelope>";

  // Set headers
  [request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  [request setValue:@"http://schemas.microsoft.com/sharepoint/soap/directory/GetCurrentUserInfo" forHTTPHeaderField:@"SOAPAction"];

  // Content length
  NSString *contentLength = [NSString stringWithFormat:@"%d", soapEnvelope.length];
  [request setValue:contentLength forHTTPHeaderField:@"Content-Length"];

  // Set body
  [request setHTTPBody:[soapEnvelope dataUsingEncoding:NSUTF8StringEncoding]];

  AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request
    success:^(AFHTTPRequestOperation *operation, id responseData) {
      NSString *xmlString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
      NSLog(@"XML response : %@", xmlString);

      // Parse the response
      SharepointCurrentUserResponse *response = ...

      successBlock(reponse);
    }
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Get user info failed with reason: %@ status code %d",
            error, operation.response.statusCode);

      failBlock(error);
  }];

  // Que operation
  [self enqueueHTTPRequestOperation:operation];
}
于 2013-05-26T16:58:03.917 回答