I’ve been tinkering with various ideas for messaging type controls when working with ATLAS controls that can use client side code to get more data from the server.
Right now you can do this sort of thing fairly easily by either using the WebServices bridge, or the PageMethods mechanism (which exposes Page methods to the client code in a way similar to Web Service method calls). The problem with this approach is that it doesn’t work well for a control developer.
If you want to build a control that retrieves data from the server you have a few not so pleasant choices right now in ATLAS:
- Create a separate Web Service
This seems to be the approach that some of the ATLAS controls are taking – you provide the service ASMX file that is used to retrieve the data and ATLAS then calls that service to retrieve the data. That’s fine if the data served requires custom creation, but it seems silly if you have a fixed set of functionality that is internal to the control itself.
Other complications with this approach are that it's not easy to call the service dynamically (ie. without a Proxy) from the client. This seems to change with every build of ATLAS too and I've yet to see an example that shows how to dynmaically call Web Service method from client code.
- Use low level WebRequest
ATLAS includes the features to make callbacks to the server directly using the WebRequest object, so you can certainly create some client side code that fires back to the server and handles the processing directly. Again this works, but as a control developer you then have to invent your own message protocol and maybe more importantly you have to figure out how to intercept that callback event on the server somehow. It needs to have an ASP.NET end point and correlating that back to the control is difficult. You could use an HTTPHandler, or another page etc. but again that’s an external resource and a resource that is essentially disconnected from the control that fired the request in the first place.
- Custom Callback mechanism
Finally, you can use some other mechanism to call back to the page. I was talking with Bertrand today about this and he mentioned Callbacks as a possible alternative. Yes, you remember those clunky Script Callbacks that are part of ASP.NET 2.0? They suck, but they can callback to a specific control. Other tools like Anthem.NET and my wwHoverPanel also can call back to a control.
None of these are very appealing choices. The first two require control vendors to force users of the control to install additional components like a separate Web Service ASMX file or install a custom page or handler somewhere. This breaks self-containment of controls and is generally a drag. The last option is doable – after internal ASP.NET controls use some of this on their own with Script Callbacks or other tool. Works, but – duh – why am I supposed to use ATLAS again? <g> I would expect the framework to take care of this for me and certainly not force me to use an external control.
What I would like to see is the PageMethods mechanism – where you can create [WebMethod] attributed methods on a form – extended into the control model. This would allow you to create custom server controls as usual with server controls rendering client side code or XmlScript for ATLAS and layout like normal. The server would then also expose the control based method via the client PageMethods proxy (or maybe a separate proxy for each Control – MyControlMethods.SomeMethod(MyParm,Callback) ).
This shouldn’t be too difficult to implement especially if there was some mechanism for the control to register itself on the page as a Callback method (of course that may be the sticking point - this would require a change in the ASP.NET binaries).
I really hope somebody at Microsoft is giving this scenario some serious thought. We may not be too concerned about this right now because most people are just playing with ATLAS and trying to get their head around the basic functionality. But once we all start getting deeper and start building controls, the callback scenario where the control needs to return data to the client based on property settings is going to become much more important.