2014-03-26 133 views
0

我想從使用EWS和Powershell的特定日曆中獲取一些信息。 我有,我用它來查詢EWS一個PowerShell功能查詢Exchange Web服務失敗,出現400錯誤請求

Function EWSSoapRequest 
{ 
    param (
     $soapRequest, 
     $exchangeServerAddress 

    ) 
    # Create the request 
    $webRequest = [System.Net.WebRequest]::Create($exchangeServerAddress) 
    $webRequest.ContentType = "text/xml" 
    $webRequest.Headers.Add("Translate", "F") 
    $webRequest.Method = "Post" 
    $webRequest.Credentials = $credentials 

    # Setup the soap request to send to the server 
    $content = [System.Text.Encoding]::UTF8.GetBytes($soapRequest) 
    $webRequest.ContentLength = $content.Length 
    $requestStream = $webRequest.GetRequestStream() 
    $requestStream.Write($content, 0, $content.Length) 
    $requestStream.Close() 

    # Get the xml response from the server 
    $webResponse = $webRequest.GetResponse() 
    $responseStream = $webResponse.GetResponseStream() 
    $responseXml = [xml](new-object System.IO.StreamReader $responseStream).ReadToEnd() 
    $responseStream.Close() 
    $webResponse.Close() 
    $responseXml 

} 

我能得到的日曆項就好列表,使用此XML:

$soapRequestOverview = @' 
<?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <t:RequestServerVersion Version="Exchange2010_SP2" /> 
     <t:ExchangeImpersonation> 
     <t:ConnectingSID> 
      <t:SmtpAddress>[email protected]</t:SmtpAddress> 
     </t:ConnectingSID> 
     </t:ExchangeImpersonation> 
    </soap:Header> 
    <soap:Body> 
    <FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"> 
     <ItemShape> 
     <t:BaseShape>IdOnly</t:BaseShape> 
     <t:AdditionalProperties> 
      <t:FieldURI FieldURI="calendar:Start"/> 
      <t:FieldURI FieldURI="calendar:End"/> 
      <t:FieldURI FieldURI="item:Subject"/> 
     </t:AdditionalProperties> 
     </ItemShape> 
     <CalendarView MaxEntriesReturned="100" StartDate="{0}" EndDate="{1}"/> 
     <ParentFolderIds> 
     <t:DistinguishedFolderId Id="calendar"/> 
     </ParentFolderIds> 
    </FindItem> 
    </soap:Body> 
</soap:Envelope> 
'@ 

這給了我在條目列表給定的日曆(我在調用Web服務函數之前替換狀態和結束日期,然後從返回的日曆項目列表中使用ItemID屬性來嘗試查詢位置等詳細信息等等。但是在這裏我遇到了問題

我ü選擇這個XML來進行查詢並像以前一樣使用EWSSoapRequest函數,但我一直收到400個錯誤請求。如果我將xml複製/粘貼到SoapUI中,那麼對於預期的數據我會得到一個響應。

$SoapRequestDetail = @' 
    <?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
     <t:RequestServerVersion Version="Exchange2010_SP2" /> 
     <t:ExchangeImpersonation> 
     <t:ConnectingSID> 
      <t:SmtpAddress>[email protected]</t:SmtpAddress> 
     </t:ConnectingSID> 
     </t:ExchangeImpersonation> 
    </soap:Header> 
    <soap:Body> 
     <m:GetItem> 
     <m:ItemShape> 
      <t:BaseShape>AllProperties</t:BaseShape> 
     </m:ItemShape> 
     <m:ItemIds> 
      <t:ItemId Id="AAMkADU3MzNlNjQxLTA3NDYtNDA4MS1hMmJhLTg5MmUxOTM2NzI3YwBGAAAAAABifraNBbAgRq+5NEGUOyNbBwBOxvhv/eH/R6wHrO/Hc4RhAAABnAHkAAChTN/6w47WS4YxX5iYDfnHAABfYm2zAAA=" /> 
     </m:ItemIds> 
     </m:GetItem> 
    </soap:Body> 
    </soap:Envelope> 
'@ 

難道只是我忽略了一些明顯的東西嗎?

回答

1

嘗試使用此XML代替

<?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/" 
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
    <soap:Header> 
    <t:RequestServerVersion Version="Exchange2010_SP2" /> 
    <t:ExchangeImpersonation> 
     <t:ConnectingSID> 
     <t:SmtpAddress>[email protected]</t:SmtpAddress> 
     </t:ConnectingSID> 
    </t:ExchangeImpersonation> 
</soap:Header> 
    <soap:Body> 
    <GetItem 
     xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" 
     xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
     <ItemShape> 
     <t:BaseShape>AllProperties</t:BaseShape> 
     </ItemShape> 
     <ItemIds> 
     <t:ItemId Id="AAAlAF" /> 
     </ItemIds> 
    </GetItem> 
    </soap:Body> 
</soap:Envelope> 

乾杯 格倫

+0

這工作完全格倫,非常感謝你 – Xenophane

相關問題