Generating Exchange Web Services Proxy Classes


It has come to our attention that there has been some confusion over the mention of EWS.dll in the SDK documentation and Intellisense file. Where can people find it? Actually, you get to generate it. The Exchange 2007 SDK describes how to generate proxy classes by using the Add Web Reference. This may be fine for some of you, but others may want more flexibility with their proxy classes. This is where wsdl.exe comes into the picture. 

Wsdl.exe parses schema and WSDL files to generate Microsoft .NET code files. These code files contain the types that act as proxies for the serialization and deserialization of the XML messages that are sent to and from the Exchange server. Wsdl.exe is included in the .NET Framework SDK and with Visual Studio 2003 and 2005. Different proxy generators create different object models; in this discussion, I will focus on wsdl.exe version 2.0.50727.42, the version that is included with Visual Studio 2005.

Instead of using wsdl.exe, you can use the Add Web References option in Visual Studio 2005 to create proxy classes. (This option will still be available in Visual Studio 2008, except that it will be well hidden). I prefer to use wsdl.exe to generate my proxy classes, for two reasons: 1) I can easily extend the proxy classes to make them easier to use, and 2) I can reuse my compiled DLL in all my Exchange Web Services projects. If I use the Add Web References option in Visual Studio, I have to regenerate the proxy classes for each project and therefore I lose any modifications that I made to the autogenerated classes. Oh, and remember that changes made to autogenerated classes are not supported by Microsoft; you are on your own with those modifications.

Let's start by finding wsdl.exe. By default, the Windows SDK installs it to C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\wsdl.exe. You can also access wsdl.exe by using the Visual Studio 2005 Command Prompt. To find the Visual Studio 2005 Command Prompt, from the Start Menu, choose All Programs | Microsoft Visual Studio 2005 | Visual Studio Tools | Visual Studio 2005 Command Prompt. Wsdl.exe has been added to the Path environment variable of the Visual Studio 2005 Command Prompt so that you can access it easily.

Now that you know where to find wsdl.exe, you can learn more about it by reading the Web Services Description Language Tool (Wsdl.exe) topic.

You are now ready to generate the proxy classes. I like to use the Visual Studio 2005 Command Prompt to access wsdl.exe as it also has the C# compiler in the path. We will use the C# compiler in a bit. In the Visual Studio 2005 Command Prompt, I use the following parameters to generate my proxy classes:

wsdl /language:cs /out:EWS.cs /namespace:ExchangeWebServices https://MyCAServer.Domain.com/ews/services.wsdl

I chose C# as the output language type for my proxy classes. You can also use Visual Basic .NET or C++ proxy classes. EWS.cs is the output code file for my proxy classes. I used ExchangeWebServices for the name of the namespace that holds all the proxy types; this is consistent with the namespace that is used in the Exchange 2007 SDK documentation and the Intellisense files that are included in the downloadable SDK. The last argument is the URL to my Exchange Web Services endpoint.

So now you have a code file with the autogenerated proxies. Next, you compile your code file into an assembly for use in your Exchange Web Services projects. The C# compiler is available with the Visual Studio 2005 Command Prompt. Assuming that you named your code file EWS.cs, you can run the following command at the command prompt to compile your code into an assembly:

csc /target:library /out:EWS.dll EWS.cs

Notice that EWS.dll is the name of the compiled assembly. This is how EWS.dll is created.

Voila! Now you have an assembly that can be reused in all your Exchange Web Service projects. If you currently use the Add Web References option in Visual Studio 2005, I recommend that you start using wsdl.exe instead to generate your Exchange Web Services proxy classes.


Comments (16)

  1. Exchange Admin 101: Exchange 2003 and Exchange 2007 admin privileges Troubleshooting Exchange Global

  2. adamc says:

    Has this changed for SP1? I create the EWS.dll following your post but the ExchangeServiceBinding class does not have a Url or Credentials property that can be seen in the SDK. Any ideas? I have actuall created the dll using both 2005 and 2008 and get the same results.

  3. qtdtrinh says:

    adamc… add System.Web.Services to your project references and in your class add using System.Net

  4. Waleed Saad says:

    Could you please send me the wsdl files of MS – Exchange 2007 my email is waleed_m_saad@hotmail.com

  5. Hello Waleed Saad,

    The WSDL file is located on your Exchange Server in the /EWS/ virtual directory.

    With regards,

    Michael Mainer

    Exchange SDK

    Microsoft Corporation

  6. JP_Kim says:

    Hi, can you confirm that a native, non-managed C++ proxy for EWS can be generated with a Microsoft proxy generator like wsdl.exe or sproxy.exe?

  7. Muhammad Shahbaz Ashraf says:

    I have to ask that when we are adding web reference of Exchange Web Services, it ask for user mail box crendentials that is fine and after that it expose the web services. My question is that after giving the user mail box crendentials all web service functions work for that user, but i have to make it dynamic i.e. i supply the user mail box crendiantals to the web service and it will work for that user how it is acheivable ? I want the function to supply the crendential of user mail box ? Is their any function available in exchange seb service ?

    Muhammad Shahbaz

    Software Engineer

    Inbox Business Technologies

    muhammad.shahbaz@inboxbiz.com

  8. Muhammad Shahbaz Ashraf says:

    I have to ask that when we are adding web reference of Exchange Web Services, it ask for user mail box crendentials that is fine and after that it expose the web services. My question is that after giving the user mail box crendentials all web service functions work for that user, but i have to make it dynamic i.e. i supply the user mail box crendiantals to the web service and it will work for that user how it is acheivable ? I want the function to supply the crendential of user mail box ? Is their any function available in exchange seb service ?

    Muhammad Shahbaz

    Software Engineer

    Inbox Business Technologies

    muhammad.shahbaz@inboxbiz.com

  9. oliver shikaloski says:

    Hi, i am also interested in native C++ proxy. Is it possible to generate the Proxy for native C++, has anybody done it already or?

    Any advice is appreciated!

    Thx

  10. I am really grateful to have the information from this blog.I liked the blog as it has been written,the information  i got from here.

    <a http://webservicesofindia.com'/&gt; Free Reciprocal Links Directory

    </a>

  11. Makarand says:

    Exchange service URL starts with https://. Hence wsdl does not work. Please help.

  12. billyc168@gmail.com says:

    Is this proxy class code can be used on Metro App ? Or exist any way to get proxy class can be build with Metro App? I am sure this code works for .NET and Desktop. However I am looking for Metro App EWS proxy class C# code.

  13. Gnanaprakash says:

    Can you guys give a explanation for what are the proxy class consist of and their purpose of each methods in that ,

    i had been searching it for a long time help me to make it clear

  14. web design and development says:

    Thanks for sharing… Very useful information is given here..

  15. Gouranga 56 says:

    Must be missing something, whe nI run the WSDL.exe command I always get 401 UnAuthorized. Have tried it a few ways, the username and password commands do not seem to be recognized either.

Skip to main content