Saying shortly I created assembly that needs minimum configuration to redirect call to any class library referenced in the web site !
I placed source code on my website - so you can download it and see how I did it, the code is too large to describe it in this post. But saying shortly I used ASP.NET AJAX framework source code, and especially the part of it where AJAX framework is using AppService.axd path to access Profile and Membership web services.
Ok lets see how you can include this functionality to your web site.
Sample solution looks like this:
Here you can see three Projects:
1) AjaxServiceLoader is the assembly that allows you to call http handlers the same way you call web services (almost the same).
2) WizardFramework - is some website on which I need to call methods from some another assembly right from the browser.
3) MyCustomAssembly - is the assembly I want to call methods in, from my web site.
MyCustom assembly contains only one simple class, the listing shows it's contents:
public objectMyMethod1(int someInteger, int anotherInteger)
returnsomeInteger + anotherInteger;
public objectMyMethod2(stringsomeString, stringanotherString)
returnsomeString + " "+ anotherString;
Ok thats all about MyCustomAssembly, now the most interesting part, how I configure WizardFramework website to use that assembly.
First to use methods inside assembly we need reference MyCustomAssembly in the website. AjaxServiceLoader should be also referenced, because we will use it to achieve what we need.
Web.config file should contain the following sections:
<httpHandlers> ... <add verb="*" path="*_LoaderService.axd" validate="false" type="AjaxServiceLoader.LoaderServiceHandler, AjaxServiceLoader"/> ... </httpHandlers>
This is needed configuration entry - it says to AjaxServiceLoader assembly that all requests ending with _LoaderService.axd should be served as script service calls.
And the second configuration where we actually define where to search for Type and method we want to execute:
first register section as follows:
type="AjaxServiceLoader.ServiceTypeDefinitionsSection, AjaxServiceLoader"allowDefinition="Everywhere"allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
And second just list which calls will be redirected to which types:
<ServiceTypeDefinitions> <serviceTypes> <clear /> <add name="SomeName" serviceKey="SomeKey" serviceType="MyCustomAssembly.SomeClass, MyCustomAssembly" /> </serviceTypes> </ServiceTypeDefinitions>
That's it, we finished configuration - you can see how easy it is, you can list there multiply types with multiply keys - even from different assemblies.
Last thing is how we use the service, so there is a listing for Default.aspx :
Also very simple, the script reference we add to ScriptManager control:
<Scripts> <asp:ScriptReference Path="~/SomeKey_LoaderService.axd/js" /> </Scripts>
As you see I use MyCustomAssembly.SomeClass.MyMethod1 and pass some integer parameters that will be passed to actual method in that assembly.
I hope you like the simplicity and will use the code as you wish. If you like the idea please provide some feedback.
Hope this helps.