2

We want to retrieve emails from our Office365 Inbox from a C# Application. We used to use EWS but want to change to Graph. However, if we retrieve an email via Graph it takes twice the time as with EWS (~400ms vs ~200ms).

Here is the EWS code:

ExchangeService service = <...>;
PropertySet properties = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.From,
                                                             EmailMessageSchema.DateTimeSent, EmailMessageSchema.Subject,
                                                             EmailMessageSchema.CcRecipients, EmailMessageSchema.BccRecipients,
                                                             EmailMessageSchema.Importance, EmailMessageSchema.ToRecipients,
                                                             EmailMessageSchema.Attachments, EmailMessageSchema.Size,
                                                             EmailMessageSchema.Sender, EmailMessageSchema.Body,
                                                             EmailSchema.MailComment, EmailSchema.MailImportance,
                                                             EmailSchema.MailMessageClass, EmailMessageSchema.DateTimeReceived,
                                                             EmailSchema.MailTransportHeader);
properties.RequestedBodyType = Microsoft.Exchange.WebServices.Data.BodyType.HTML;
EmailMessage mail = EmailMessage.Bind(service, "<mailid>", properties);

Here is the Graph code:

GraphServiceClient client = <...>;
Message msg = client
               .Users["<user>"]
               .Messages["<mailid>"]
               .Request()
.Select("id,parentFolderId,isRead,from,sentDateTime,subject,ccRecipients,bccRecipients,attachments,importance,toRecipients,sender,body,receivedDateTime")
            .Expand("microsoft.graph.message/attachments," +
                "singleValueExtendedProperties($filter=Id eq 'Long 0xe08'" +
                " or Id eq 'String 0x1a'" +
                " or Id eq 'String 0x7d'" +
                " or Id eq 'Integer 0x17'" +
                " or Id eq 'String 0x3004')")
            .GetAsync()
            .Result;

Why is Graph slower? What should we change to make Graph as performant as EWS?

  • When you execute the same endpoint on [Graph Explorer](https://aka.ms/ge) or Postman and seen the same response time? – Danstan Jun 14 '21 at 05:48

2 Answers2

0

We found out that only the first access to the mail server takes longer via Graph. Every following request is at least as performant as via EWS. So the issue is resolved for us. Thank you @Danstan for your comment.

0

My guess is that the graph api will never be faster then the EWS api.

The graph api is “just” (not the right word) a really fancy and blazing fast api proxy combining all available resources to one api.

So if you call the graph api, the following happens: Your request -> graph api -> Exchange rest api

The only change is that by using the graph api the data is formatted as JSON at the server level. So that might be a small time/data saver

Stephan
  • 2,356
  • 16
  • 38