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
Anonymous
December 07, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/12/07/generating-exchange-web-services-proxy-classes/Anonymous
December 15, 2007
Exchange Admin 101: Exchange 2003 and Exchange 2007 admin privileges Troubleshooting Exchange GlobalAnonymous
January 23, 2008
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.Anonymous
January 29, 2008
adamc... add System.Web.Services to your project references and in your class add using System.NetAnonymous
February 02, 2008
Could you please send me the wsdl files of MS - Exchange 2007 my email is waleed_m_saad@hotmail.comAnonymous
February 04, 2008
Hello Waleed Saad, The WSDL file is located on your Exchange Server in the /EWS/ virtual directory. With regards, Michael Mainer Exchange SDK Microsoft CorporationAnonymous
February 22, 2008
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?Anonymous
March 12, 2008
The comment has been removedAnonymous
March 12, 2008
The comment has been removedAnonymous
June 24, 2008
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! ThxAnonymous
August 08, 2010
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'/> Free Reciprocal Links Directory </a>Anonymous
April 13, 2011
Exchange service URL starts with https://. Hence wsdl does not work. Please help.Anonymous
February 20, 2013
The comment has been removedAnonymous
February 19, 2014
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 clearAnonymous
May 04, 2014
Thanks for sharing... Very useful information is given here..Anonymous
May 12, 2014
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.