Service Framework (SF) isn’t easily accessible to the Installer as initialization of the service routes depends on something that isn’t available during Installation. It is possible to tweak here and there to make SF available during Installation, but that would have resulted in unnecessary overhead with a corresponding increase in installation time – the opposite of our goals for the new Installer.
Turns out that Asp.Net has a little known Ajax method called as WebMethod. Webmethod provides easily callable APIs from the web client without the need for web services, wcf or mvc. That turned out to be actually pretty simple to use.
A WebMethod is simply a server side ASP.NET page method that can be called by client script. Not only is the method integrated with your page code (convenient for small applications) but the ASP.NET compiler automatically adds client-side methods that take care of the AJAX request, JSON encoding and, to a degree, data type conversion. Sure, you could do this using a web service and XmlHttpRequest - but this is a quick-and-easy way of AJAX-enabling standard web form pages.
The handy thing about the WebMethod is that, assuming ASP.NET 3.5 is setup in your web.config, the development requirement and learning curve are minimal. In short, to create a WebMethod you must do three things:
1.Import the System.Web.Services namespace on your page.
2.Add the [WebMethod] attribute to a static page method.
3.Add a ScriptManager control with the EnablePageMethods property set to true.
After that, it's just a matter of calling the function from JavaScript, which can be accessed as a client-side method off a PageMethods object that ASP.NET automatically generates. This method automatically includes overloads for two optional parameters, a success and fail function.
Code Behind
[System.Web.Services.WebMethod]
public static void RunInstall()
{
LaunchAutoInstall();
}
Client Side
//Call PageMethod which triggers long running operation
PageMethods.RunInstall(function () {
}, function (err) {
$.stopProgressbarOnError();
});
Interested readers can find sample code around use of WebMethod, in /Install/InstallWizard.aspx and InstallWizard.aspx.cson thecodeplex source repository (http://dotnetnuke.codeplex.com/SourceControl/changeset/view/69709#546346).
Currently rated 0.0 by 0 people