그래서 동일한 교환 웹 서비스 예제로 설정 한 :EWS는 PowerShell에서 작동하지 않습니다
C# 버전은 콘솔 응용 프로그램으로 실행 :
class Program
{
static void Main(string[] args)
{
var es = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
TraceEnabled = true,
UseDefaultCredentials = true,
Url = new Uri("https://mail.myServer.com/EWS/Exchange.asmx")
};
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
var inboxId = new FolderId(WellKnownFolderName.Inbox);
Folder inboxFolder = null;
try
{
inboxFolder = Folder.Bind(es, inboxId);
} catch(Exception e)
{
Console.Out.WriteLine(e.Message);
}
if (inboxFolder == null)
{
Console.Out.WriteLine("FAILED");
return;
}
Console.Out.WriteLine("Total stuff: [{0}]", inboxFolder.TotalCount);
Console.In.ReadLine();
}
}
파워 쉘 버전 :
clear
# Load EWS Managed API
Import-Module "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll";
$EWSService = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2)
$EWSService.traceenabled = $true
$EWSService.UseDefaultCredentials = $true
$EWSService.Url = New-Object Uri("https://mail.myServer.com/EWS/Exchange.asmx")
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true };
$InboxID = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
Try {$InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($EWSservice,$InboxID)}
Catch [Exception] {
Write-Host $_.Exception.Message
}
둘 다 동일한 시스템, 동일한 사용자에서 실행됩니다. 콘솔 앱은 데이터를 연결하고 반환합니다. powershell 버전은 매우 유용한 메시지를 얻습니다.
The request failed. The underlying connection was closed: An unexpected error occurred on a send.
예외 검사는 추가적인 정보를 제공하지 않습니다. 두 버전 모두 동일한 EWS 관리 API를 참조합니다. 누구나 이것이 왜 그런지 아이디어가 있습니까?
난 :
내가 이렇게 내 EWS 스크립트에서 그 .DLL을로드 형을 추가 사용 EWS의 전문가는 아니지만 [System.Net.ServicePointManager] :: ServerCertificateValidationCallback = {$ true}; 이 보이지 않습니다. AutoDiscover를 사용하여 Exchange 서버를 찾을 때 사용되는 것으로 만 보았지만 서버 이름은 이미 URI에 하드 코딩되어 있습니다. – mjolinor
제 사용법에서, 이것은 서버가 서명되지 않은 인증서를 사용할 때 인증서 오류를 무시하는 데 사용됩니다. 비록 내가 틀렸다고하더라도, 코드는 .NET에서 작동하고 Powershell에서는 작동하지 않으므로 콜백이 문제가되어서는 안된다. – Bitfiddler
오늘 같은 문제가 발생했습니다. 표준 Windows PowerShell 콘솔과 SharePoint 2013 PowerShell 콘솔에서 동작이 다른 것으로 나타났습니다. 특히 [여기] (http://social.technet.microsoft.com/Forums/en-AU/exchangesvrdevelopment/thread/ad493b72-6465-450b-bd49-8f15675d7f53)에 설명 된 솔루션은 Windows PowerShell에서는 작동하지만 SharePoint에서는 작동하지 않습니다. 하나. 링크가 깨져서 Google 캐시에서 페이지를 가져 왔습니다. – johnnyjob