locked
How to use Exchange Web services managed API? RRS feed

  • Question

  • I have downloaded 64 bit EWSManagedApi. In my VS project, I added the reference and using statement (using Microsoft.Exchange.WebServices.Data;). However, when compiling the code, I got the error "The type or namespace name 'Exchange' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)".

    I'm a newbie on Exchange Server. What else am I missing?
     
    Thanks in advance!!!

    Monday, July 2, 2012 7:45 PM

Answers

  • Try this simple console application:

    using Microsoft.Exchange.WebServices.Data;
    using System;
    using System.Net;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Enter the password");
                string strPassword = Console.ReadLine();
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = new NetworkCredential("sliu", strPassword, "cpu2");
                service.AutodiscoverUrl("sliu@cpu2.com");
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
                foreach (Item item in findResults.Items) Console.WriteLine(item.Subject);
            }
        }
    }
    
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Marked as answer by s liu Thursday, July 5, 2012 5:54 PM
    Tuesday, July 3, 2012 2:10 PM

All replies

  • What version of Visual Studio?

    Can you share a little more about your code?

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Monday, July 2, 2012 8:24 PM
  • I'm using VS 2010 and .Net Framework 4.0. I realized Microsoft.Exchange.WebServices was build on .Net Framework 3.5. After I switched to Framework 3.5 for my project, it compiled fine. Then I got another runtime error :The Autodiscover service couldn't be located. Following is my code:

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = new NetworkCredential("sliu", tbPasswd.Text, "cpu2.com");
                service.AutodiscoverUrl("sliu@cpu2.com");
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
                foreach (Item item in findResults.Items) Console.WriteLine(item.Subject);
    

    Monday, July 2, 2012 9:38 PM
  • Try this simple console application:

    using Microsoft.Exchange.WebServices.Data;
    using System;
    using System.Net;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Enter the password");
                string strPassword = Console.ReadLine();
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = new NetworkCredential("sliu", strPassword, "cpu2");
                service.AutodiscoverUrl("sliu@cpu2.com");
                FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
                foreach (Item item in findResults.Items) Console.WriteLine(item.Subject);
            }
        }
    }
    
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    • Marked as answer by s liu Thursday, July 5, 2012 5:54 PM
    Tuesday, July 3, 2012 2:10 PM
  • I tried. The same error happened.
    Tuesday, July 3, 2012 5:00 PM
  • Is sliu@cpu2.com a valid email address?
    Is the domain name in Active Directory cpu2?
    do you login as cpu2\sliu?

    The code runs fine under Visual C# 2010 express edition when I set it to target .Net Framework 3.5 or 4.0

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Tuesday, July 3, 2012 5:39 PM
  • It is valid email address and valid domain. I login as cpu2\sliu.

    I can only run it under .Net Framework 3.5. Framework 4.0 doesn't recognize Microsoft.Exchange.WebServices even though there is reference to that dll.

    Do I need to install other software to make ExchangeService.AutodiscoverUrl work? I have VS 2010 Ultimate edition.

    Thanks for your help!!!

    Tuesday, July 3, 2012 7:01 PM
  • Problem is solved. I used wrong domain.
    Thursday, July 5, 2012 5:53 PM