Wednesday, September 10, 2003

DNN Functionality as a Web Service?

Are you one of those "forward" thinkers? If so, you may have already asked "Why can't I use web services in DotNetNuke?" Well, I have been asking the same question for months and come up with one way of addressing this with Core DNN until such time that the core supports this.


One of the problems with DNN and including .asmx web service files is that the URL rewriter does not take web services into consideration. This rewriter has been a blessing to many but a bane to web services. One way of address this is to look at a comparison between current Desktop Modules and Webservice modules.


If we consider the fact that the desktop modules for DotNetNuke are nothing more than controls and files in a subdirectory of /desktopmodules that inherit from a DNN class. Now why should web services not be a similar animal? They should. So the solution that follows builds upon this conept with a simple core change.


Under the root of your DotNetNuke installation, create a new directory called /WebServices. This will be analagous to the /DesktopModules directory. All web services you wish to use will be in an aptly named sub directory of the /WebServices directory. So for our example web service called "HelloWorld" we create a directory called "HelloWorld" under the /WebServices directory.


Now that the new home for the web service has been created, we need to add the associated files to actually perofrm the web service functions. Copy your .asmx file to the /WebServices/HelloWorld directory. You also have a compiled .dll file from your web service project. This goes into the /bin directory just like any other private assembly .dll file.


Finally we have all the files and directories in place. Now we must deal with the URL rewriter. A simple method of doing this is to make the following modification to the globals.vb file. This modification is in the spirit of the original framework. What we are doing here is explicitly telling the DNN core to treat the /webservices directory just like the desktopmodules directory. This way, the web service files can be called just like .aspx files in the desktopmodules directory.


Modification to Line 62 of Globals.vb

Case "admin", "controls", "desktopmodules", "mobilemodules", _
"premiummodules", "webservices"


That is all there is to it. Just recompile your DNN Core project and you are ready. This change essentially allows Private Assemblies in theory could add dll's to /bin, .ascx and aspx pages to /desktopmodules/mymodulename/ and .asmx to /webservices/mymodulename. This
opens the doors for DNN to now provide services to other platforms or site using web services.

No comments: