使用证书和 C# 连接到 Exchange Online

Kev*_*n C 5 c# exchange-server office365

有人使用 C# 在线连接 Exchange 吗?我遇到了一个似乎无法取得进展的问题。

我有以下代码片段尝试连接到在线交换:

public Runspace getSpace() {
    String schema = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
    Uri server = new Uri("https://outlook.office365.com/PowerShell");
    string certificateThumbprint = "thumbprint";

    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(server, schema, certificateThumbprint);
    Runspace rsp = RunspaceFactory.CreateRunspace(connectionInfo );
    rsp.Open();
    return rsp;
}
Run Code Online (Sandbox Code Playgroud)

结果是:

System.Management.Automation.Remoting.PSRemotingTransportException:
连接到远程服务器 Outlook.office365.com 失败,并出现以下错误消息:有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。在 System.Management.Automation.Runspaces.AsyncResult.EndInvoke()

我知道证书正在工作,因为当我执行以下操作时,我可以连接:

Connect-ExchangeOnline -AppId "application guid" -Organization "tenent.onmicrosoft.com" -CertificateThumbprint "thumbprint"
Run Code Online (Sandbox Code Playgroud)

关于我下一步可以尝试什么有什么想法吗?谢谢!

Eug*_*iev 0

考虑使用EWSGraph API