I'm going to take a quick detour from WSDAPI 101 to comment on an issue you may have seen when developing and testing a service or client based on WSDAPI.
The symptoms of this crashThis problem may arise in two scenarios:
In both cases, this problem only applies to applications running on the desktop version of WSDAPI (i.e., under Windows Vista or Server 2008). This does not apply to WSDAPI-based apps running under Windows CE.
You may see this manifest in a handful of different ways:
The explanation behind the crash In all cases, the cause is the same: a difference in the calling convention is causing your service method (or client-side event sink) to corrupt the stack when it returns control to WSDAPI. WSDAPI expects that your service method will use the __stdcall calling convention, but it's common for applications to be compiled with __cdecl (or even __fastcall) conventions, especially if built in Visual Studio.
How to fix this crashTo fix this problem, you need to change your compilation options to use __stdcall (/Gz) instead of other calling conventions. Since this problem is most prevalent in the Visual Studio build environment (which defaults to __cdecl), here are directions for fixing this in VS 2005:
At right is a screenshot that describes this property page and the changes you need to select. The areas of interest are highlighted in red.
We're also going to fix this for the next version of WsdCodeGen, so you can use whatever calling convention you'd like in your application. Until then, changing this option will allow your service methods to safely return without crashing the application.