有没有办法获得UserGroup.GetUserInfo
的结果,但无需指定我要查询的用户,例如使用UserGroup.GetRolesAndPermissionsForCurrentUser
?
特别是,我正在尝试获取用户ID(以便我可以判断文档是否已签出给当前登录的用户,或者不是)。不幸的是,我使用智能卡提供凭据 - 没有为实际文档库输入用户名或密码 - 所以我不能使用域\用户名GetUserInfo
,这是我如何为非 - 智能卡使用。
此外,我在iOS上,所以我真的没有任何好的SharePoint API可供使用 - 一切都需要通过2007/2010 SOAP WebService API提供
谢谢!
答案 0 :(得分:1)
您应该可以使用UserGroup.GetCurrentUserInfo
。
可以在此处找到Sharepoint SOAP文档http://msdn.microsoft.com/en-us/library/websvcusergroup.usergroup.getcurrentuserinfo(v=office.14).aspx。
如果您有权访问Sharepoint实例,可以在此处检查SOAP信封和响应: https://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];
}