Pregunta

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

    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

}

I can get the list of calendar items just fine, using this 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>user@domain.dk</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>
'@

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.

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.

    $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>user@domain.dk</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>
'@

Is it just me overlooking something obvious ?

¿Fue útil?

Solución

Try using this XML instead

<?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>user@domain.com</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>

Cheers Glen

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top