Asmx (RSS)

asmx endpoint (prior to WCF)

Generally, when creating a service to be exposed as a web service, I have built the entire service project(s) (including datacontract/entity classes) outside of any web project, in a separate solution. These projects can then be built and tested without any web project getting involved. I then usually create a separate web project, that acts solely as a http end point, and which references and uses the actual web service project(s) . To facilitate this, there is a 1:1 mapping in the asmx code behind which simply defines the webmethod and passes through or calls upon the real service class. What a waste of time and useless code.

When using the Patterns & Practices Web Service guidance, I noticed that just like I have always done, the real service classes are created in their own projects outside of the scope of a web project (for numerous good reasons), but I noticed that in the actual web project classes there was no code behind, and therefore no 1:1 mapping of each web method to the real service method. As simple as the explanation is, I scratched my head for a few minutes trying to determine how the actual service classes were getting invoked? In the words of Homer, "Doh!" In the Asmx @Webservice directive there is no codebehind attribute, and the class= attribute just references the fully qualified class name that implements the actual service methods. This requires the actual service project references system.web, and also requires that the public web method attributes are marked accordingly. But this is fine because the goals of separating the service implementation from the end point project are still accomplished, all without the useless 1:1 mapping in the codebehind.

Sometimes its the simple things. Oh well, I finally realize this now that .Net 3 is available and WCF changes the way we declare endpoints altogether. But, I wish I had realized this simple asmx endpoint trick a while back : -)

Asynchronous web methods used with @Page Async=True

Its seems most of my development these days involves some form of modular parts assembled at runtime in Windows SmartClient apps, or at Page Load time in customizable web part portal applications. In web portal apps, that are built out of independent web parts, page performance can degrade linearly with the number of parts included on any one page. Generally, if each of these parts is treated as a true module or smart web part then they are usually each responsible for getting their own data. Because of this, I find myself doing a lot more asynchronous work during page processing so that all the parts can come together in parallel within a reasonable amount of time. The trick is to not tie up the main worker thread as it waits for your async parts to finish, so that it can go back and handle other page requests. Asp.Net 2.0 enables this process with the Async=True page attribute. However, there is a little additional magic that happens behind the scenes when using web services via proxies that were created with Asp.Net 2.0 web references.

When adding a web service reference to .Net 2.0 Asp.Net app, you may notice that for each web method there is a "async" method also created in the reference file. Since .Net 1, we have gotten both the standard synchronous method implementation, and also the corresponding Begin/End async methods (following the standard IAsyncResult pattern). However, in .Net 2.0, web references also create a third choice, which uses a delegate callback pattern. When this async method is used to populate a control in conjunction with a web page marked with the Async="True" Page directive, some interesting stuff happens. Behind the scenes, when the async version of the method is called on the web proxy, "InvokeAsync" of the proxy's SoapHttpClientProtocol base class is called, which in turn registers this call with .Net 2.0's AsyncOperationManager. If you have been using the Async=True page directive in Asp.Net 2, you are probably familiar with calling Page.RegisterAsyncTask to do some async work. For those not familiar with this, Async=True will allow a page to process up to pre-render, but then it will relinquish its main Asp.Net processing thread, until it's registered async tasks finish. The powerful thing about using the new async web methods, is that this call to RegisterAsyncTask is wired up implicitly for you. So, you mark a page with the Async=True attribute, call upon the asynchronous version of the web method, and the RegisterAsyncTask is wired up for you.

Fritz explains this awsome feature in detail in his June Extreme Asp.Net article.