Skip to content

Instantly share code, notes, and snippets.

@fischerman
Last active August 29, 2015 14:24
Show Gist options
  • Save fischerman/0b97878c32bfefda8548 to your computer and use it in GitHub Desktop.
Save fischerman/0b97878c32bfefda8548 to your computer and use it in GitHub Desktop.
Reproduce error with EWS on mono
FROM mono:onbuild
CMD [ "mono", "./ewsTest.exe" ]
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ewsManageedTest
{
class Program
{
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Url = new Uri("");
service.Credentials = new WebCredentials("", "");
var subscription = service.SubscribeToStreamingNotifications(
new FolderId[] {new FolderId(WellKnownFolderName.Calendar, "")},
EventType.Created,
EventType.Deleted,
EventType.Modified
);
service.TraceListener = new Tracer();
service.TraceFlags = TraceFlags.EwsResponse | TraceFlags.EwsRequest;
service.TraceEnabled = true;
StreamingSubscriptionConnection conn = new StreamingSubscriptionConnection(service, 10);
conn.AddSubscription(subscription);
conn.OnDisconnect += conn_OnDisconnect;
conn.OnNotificationEvent += conn_OnNotificationEvent;
conn.OnSubscriptionError += conn_OnSubscriptionError;
conn.Open();
Thread.Sleep(TimeSpan.FromHours(1));
}
static void conn_OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
{
}
static void conn_OnNotificationEvent(object sender, NotificationEventArgs args)
{
}
static void conn_OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
if (args.Exception != null)
throw args.Exception;
}
}
class Tracer : ITraceListener
{
public void Trace(string traceType, string traceMessage)
{
Console.WriteLine(" [ T ] type: {0} \n {1} ", traceType, traceMessage);
}
}
}
Copy link

ghost commented Jul 17, 2015

Tried this against a Exchange 2013 box I have. Running as a test within Visual Studio.
Requested 2010_SP2 mode from the server as in your code.
Seems to work just fine, no problem.

Maybe a mono-specific problem.

Response message:

<Trace Tag="EwsResponse" Tid="4" Time="2015-07-17 18:44:19Z" Version="0.0.0.0">
  <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <soap11:Header xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
      <ServerVersionInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="0" MajorBuildNumber="775" MinorBuildNumber="35" Version="V2_4" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
    </soap11:Header>
    <soap11:Body xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
      <m:GetStreamingEventsResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
        <m:ResponseMessages>
          <m:GetStreamingEventsResponseMessage ResponseClass="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:ConnectionStatus>OK</m:ConnectionStatus>
          </m:GetStreamingEventsResponseMessage>
        </m:ResponseMessages>
      </m:GetStreamingEventsResponse>
    </soap11:Body>
  </Envelope>
</Trace>
<Trace Tag="EwsResponse" Tid="5" Time="2015-07-17 18:44:19Z" Version="0.0.0.0">
  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="775" MinorBuildNumber="35" Version="V2_4" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <m:SubscribeResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <m:ResponseMessages>
          <m:SubscribeResponseMessage ResponseClass="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:SubscriptionId>FgBpc3Rlc3QtZXhjaC0wMi5sYWIyLmFkEAAAABuwHn9qVLdHp6OeqjbWzjcZAE2M147SCA==</m:SubscriptionId>
          </m:SubscribeResponseMessage>
        </m:ResponseMessages>
      </m:SubscribeResponse>
    </s:Body>
  </s:Envelope>
</Trace>

Copy link

ghost commented Jul 17, 2015

Downloaded latest mono release on windows and created a console program, ran it in the mono command prompt, still works fine. I'm now more inclined to think that something has been fixed between Exchange 2010 SP2 and Exchange 2013, since I can't replicate the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment