2

经过大量搜索,我发布了这个问题。

问题来了。。

我正在使用 EWS 通过 AutoDiscover 将联系人导入到 MAC 应用程序。

这是我的 XML 请求

      NSString *soapMessage = [NSString stringWithFormat:
                         @"<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006/\">"
                         "<Request>"
                         "<EMailAddress>%@</EMailAddress>"
                         "<AcceptableResponseSchema>"
                         "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"
                         "</AcceptableResponseSchema>"
                         "</Request>"
                         "</Autodiscover>",self.emailId.stringValue];
NSLog(@"%@",soapMessage);

NSURL *url = [NSURL URLWithString:@"https://<domainname>/EWS/Exchange.asmx"];

以上只是片段。已完整通过其他标头。

我的问题是在 C# 中传递用户凭证时,究竟在哪里传递,如下所示

 ExchangeServiceBinding esb = new ExchangeServiceBinding();
 esb.Credentials = new NetworkCredential("<username>", "<password>", "<domain>");

我尝试使用质询身份验证,也尝试使用在标头授权中发送它。但没有运气。

非常感谢任何帮助实现这一目标。

4

2 回答 2

4

它的全部内容是构建对 EWS 的正确 XML 请求。而已..

使用https://www.testexchangeconnectivity.com/获取邮件、联系人、日历以进行测试。

检查它生成的请求,将其复制到 XML 的标头部分中。

它像微风一样工作..

发布此内容以节省一些非窗口开发人员的时间。

于 2013-09-20T11:23:20.980 回答
0

实际上,挑战身份验证适用于 Exchange Web 服务。EWS 使用 ServerTrust 和 NTLM 身份验证。以这种方式实现 NSURLConnectionDelegate 方法:

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    if ( challenge.previousFailureCount > 0 )
    {
        // handle authentication error here, e.g. NSError *authError = ...;
        return;
    }

    // username and password should be stored as ivars.
    NSString *username = @"your_username";
    NSString *password = @"your_password";

    NSURLCredential *urlCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession];

    [challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge];
}


- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
    // Should return YES for NTLM and ServerTrust methods.
    NSString *authMethod = protectionSpace.authenticationMethod;
    return ([authMethod isEqualToString:NSURLAuthenticationMethodServerTrust] ||
            [authMethod isEqualToString:NSURLAuthenticationMethodNTLM] );
}
于 2014-05-24T14:09:16.647 回答