title: Querying Exchange Web Services fails with 400 Bad Request
body: <p>I am trying to get some information from a specific calendar using EWS and Powershell.
  I have a powershell function that I use to query EWS</p>
  
  <pre><code>    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
  
  }
  </code></pre>
  
  <p>I can get the list of calendar items just fine, using this XML:</p>
  
  <pre><code>$soapRequestOverview = @'
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;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/"&gt;
      &lt;soap:Header&gt;
        &lt;t:RequestServerVersion Version="Exchange2010_SP2" /&gt;
        &lt;t:ExchangeImpersonation&gt;
          &lt;t:ConnectingSID&gt;
            &lt;t:SmtpAddress&gt;user@domain.dk&lt;/t:SmtpAddress&gt;
          &lt;/t:ConnectingSID&gt;
        &lt;/t:ExchangeImpersonation&gt;
      &lt;/soap:Header&gt;
    &lt;soap:Body&gt;
      &lt;FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"&gt;
        &lt;ItemShape&gt;
          &lt;t:BaseShape&gt;IdOnly&lt;/t:BaseShape&gt;
          &lt;t:AdditionalProperties&gt;
            &lt;t:FieldURI FieldURI="calendar:Start"/&gt;
            &lt;t:FieldURI FieldURI="calendar:End"/&gt;
            &lt;t:FieldURI FieldURI="item:Subject"/&gt;
          &lt;/t:AdditionalProperties&gt;
        &lt;/ItemShape&gt;
        &lt;CalendarView MaxEntriesReturned="100" StartDate="{0}" EndDate="{1}"/&gt;
        &lt;ParentFolderIds&gt;
          &lt;t:DistinguishedFolderId Id="calendar"/&gt;
        &lt;/ParentFolderIds&gt;
      &lt;/FindItem&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  '@
  </code></pre>
  
  <p>That gives me a list of entries in the given calendar (I replace the state and end date before calling the web service function. Then from the list of calendar items returned I use the ItemID property to try and query detailed information like location etc. But it is here I run into problems.</p>
  
  <p>I use this XML to make the query and use the EWSSoapRequest function as before, but I keep getting 400 Bad request back. If I copy/paste the xml into SoapUI then I get a response just fine with the expected data.</p>
  
  <pre><code>    $SoapRequestDetail = @'
    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;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/"&gt;
      &lt;soap:Header&gt;
        &lt;t:RequestServerVersion Version="Exchange2010_SP2" /&gt;
        &lt;t:ExchangeImpersonation&gt;
          &lt;t:ConnectingSID&gt;
            &lt;t:SmtpAddress&gt;user@domain.dk&lt;/t:SmtpAddress&gt;
          &lt;/t:ConnectingSID&gt;
        &lt;/t:ExchangeImpersonation&gt;
      &lt;/soap:Header&gt;
      &lt;soap:Body&gt;
        &lt;m:GetItem&gt;
          &lt;m:ItemShape&gt;
            &lt;t:BaseShape&gt;AllProperties&lt;/t:BaseShape&gt;
          &lt;/m:ItemShape&gt;
          &lt;m:ItemIds&gt;
            &lt;t:ItemId Id="AAMkADU3MzNlNjQxLTA3NDYtNDA4MS1hMmJhLTg5MmUxOTM2NzI3YwBGAAAAAABifraNBbAgRq+5NEGUOyNbBwBOxvhv/eH/R6wHrO/Hc4RhAAABnAHkAAChTN/6w47WS4YxX5iYDfnHAABfYm2zAAA=" /&gt;
          &lt;/m:ItemIds&gt;
        &lt;/m:GetItem&gt;
      &lt;/soap:Body&gt;
    &lt;/soap:Envelope&gt;
  '@
  </code></pre>
  
  <p>Is it just me overlooking something obvious ?</p>