If you have added a Web Reference for a Web Service recently you may have noticed that the wsdl tool no longer creates Begin
and End methods for you, instead it implements what is known as the Event based
Async Pattern. Which is fine if you are building a Windows or Console application, but if you are trying to call a web service asynchronously using the AddOnPreRenderAsync or RegisterAsyncTask methods in ASP.NET you really need a Begin method that returns an IAsyncResult Interface. There are several ways you can work around this.
You could, assuming you still have it, create a project in Visual Studio 2003, add the web reference there and copy it to your 2005 project, or you can run the wsdl tool manually and use the /parameters option to
specify a configuration file with the "oldAsync" flag. For example, for a reference to http://my.server.com/service, which creates a proxy class with both begin/end (a.k.a. "old style") and
event-based (a.k.a. "new style") methods, you'd use the command
wsdl.exe /parameters:MyParameters.xml http://my.server.com/service
Where MyParameters.xml is as below:
MyParameters.xml:
<wsdlParameters xmlns="http://microsoft.com/webReference/">
<nologo>true</nologo>
<parsableerrors>true</parsableerrors>
<sharetypes>true</sharetypes>
<webReferenceOptions>
<verbose>false</verbose>
<codeGenerationOptions>properties oldAsync newAsync</codeGenerationOptions>
<style>client</style>
</webReferenceOptions>
</wsdlParameters>
However, my preferred method is to set a project level property WebReference_EnableLegacyEventingModel to true.
To
do that, you need unload the project from Visual Studio, and edit the project file
directly in a text editor. (I recommend creating a backup first)
In the first section of PropertyGroup, you will see many properties like:
<ProjectGuid>{F4DC6946-F07E-4812-818A-F35C5E34E2FA}</ProjectGuid>
<OutputType>Exe</OutputType>
...
Don't change any of those, but do add a new property into that section:
<WebReference_EnableLegacyEventingModel>true</WebReference_EnableLegacyEventingModel>
Save the file, and reload the project into Visual Studio.
After that, you have to regenate all proxy code (by updating the reference, or running the custom tool on the .map file)
This is my preferred method because unlike the others I described, this one lets you refresh or update the web reference as normal, which if your project is shared with other developers is a big plus!