0

I have in my c# application a new web service that I generated using Add Web Reference tool.

It is called ExchangeWebServices in my Solution Explorer.

But when I try to add the sample code that I found on StackOverflow: 652549: read-ms-exchange-email-in-c-sharp it won't compile.

I have a compile error message that

ExchangeWebServices is a namespace but is used as a type.

here is the line of code that I am trying to use.

ExchangeWebServices service =new ExchangeWebServices(ExchangeVersion.Exchange2013_SP3);

I have at the top of my form class this:

using email2case_winForm.ExchangeWebServices;

what am I doing wrong here please?

Community
  • 1
  • 1
Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148

2 Answers2

1

I am going to guess that the code in the answer to the other stack isn't quite correct, but is more of a concept for how things could be written (Edit - Or its written against an older version of EWS). Either way, there are some excellent examples here: http://msdn.microsoft.com/en-us/library/office/bb408521(v=exchg.140).aspx.

Taking the guts of it, you should probably end up with something like:

// Identify the service binding and the user.
ExchangeServiceBinding service = new ExchangeServiceBinding();
service.RequestServerVersionValue = new RequestServerVersion();
service.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010;
service.Credentials = new NetworkCredential("<username>", "<password>", "<domain>");
service.Url = @"https://<FQDN>/EWS/Exchange.asmx";

From there you can use the service to create requests or whatever it is you need to do. Note this code was copied from the msdn link above so you'll want to refer back to that for further explanation. Best of luck!

drew_w
  • 10,320
  • 4
  • 28
  • 49
1

Instead of using the Add Web Reference tool to generate the Web service client, I highly suggest that you use the EWS Managed API instead. It is a much easier object model to use and it has some useful business logic built into it. It will save you time and lines of code.

Michael Mainer
  • 3,387
  • 1
  • 13
  • 32
  • any thoughts on [SO: searchFilter not working properly with EWS FindItems method call](http://stackoverflow.com/questions/22559704/searchfilter-not-working-properly-with-ews-finditems-method-call) ? – Our Man in Bananas Mar 21 '14 at 15:08