How to call a DLL via URL

Posted on 2009-12-16
Last Modified: 2012-05-08
Basically how does one achieve the functionality similar to that of Ebay, USPS, UPS, FedEx etc where the url is something similar to http://[url].com/SomeDLL.dll?Data=[somedata]
Question by:itbox
    LVL 51

    Expert Comment

    It's actually quite easy.  The way IIS (or any web server) works is a simple protocol (HTTP) that uses simple verbs in a text string to communicate.  Two of the key ones you use all the time are GET (to request a page) and POST (to submit a page)

    IIS and Apache are really a type of dispatcher.  They receive the GET requests and follow a few simple rules to fulfill the page request.  Within the configuration file handlers are mapped to specific verbs (GET, POST ...) for different file extensions.  You can even register wildcard (*) handlers for each web application.

    The file handlers are a simple look up table.  The web server parses the incoming URL and using the extension tries to find a matching handler.  As it happens all web servers can handle the default extensions like HTM, HTML et cetera.

    So in IIS if you create an ASP.NET web application .aspx file request are redirected to a custom ISAPI .NET DLL to process the request.  The .NET ISAPI DLL runs the server side code in the page and sends it to the client.

    However, what is really cool is you can register any custom extension you want and even avoid using files on the hard drive.  You can actually process requests in compile code and write HTML directly to the HTTP output stream.

    Sharepoint does that, so do many other applications.  In fact, REST web services are based on this very principal.

    So, if you are a .NET, C or C++ developer you can write your own custom file handlers to process URL GET or POST requests.  In .NET it's real easy.

    Author Comment

    Hi Ted,
       Yes implementing HTTP Modules/Handlers to handle custom file extensions is quite easy but registering a custom extension requires you to map the extension to some ISAPI filter. Lets say that I have an assembly wrote in C# called 'SuperAwesomeImageResizer' and there is a method in the DLL that takes three parameters: FileName, NewWidth, NewHeight.  If was working with this assembly directly in a class file it is a trivial matter to add a reference to the assembly, and create an instance of the appropriate class within the assembly to use its functionality.

    For the sake of argument lets say there is a console application running on a server and it is its job to make an HTTP Request to the webserver where the SuperAwesomeImageResizer is located and, rather then making a request to say ImageProcessor.aspx which takes values out of the POST and passes it to SuperAwesomeImageResizer, I want to make the request directly to the dll in the form of:

    So that is the question.  Is it possible to call that dll directly from the URL and, if you can, how do you setup the DLL's entry point so that the webserver knows how to handle it?

    Also, using the HTTP Module/Handler route calling superawesomeimageresizer.dll is something of smoke and mirrors. The reason I say this is because when the HTTP request comes in the custom HTTP Module/Handler will pick up and attempt to process the request.  Not a huge deal, internally the Module/Handler will have a reference to the SuperAwesomeImageResizer and the module/handler will just pull the data out of the query string and pass it into the appropriate method. Ok fine that solves my intial question, the URL doesn't exactly invoke the DLL directly but that is ok.  Now lets say next month I create a new assembly called SuperSuperAwesomeImageResizer but I still need the original SuperAwesomeImageResizer available.

    Now I have to write logic in my module/handler to figure out which DLL it needs to call internally. This is going to get messy since I will need to parse the URL to get the referenced DLL and then write a switch to call the appropriate method.  I can fix the need to parse the url by formating the request to something like: and use the value of version to determine which dll to call but I would still need the switch statement.   In this example the code for the module/handler isn't all that crazy since it is only handling two cases but what if there were, say, 30 different assemblies that could get called the switch statement becomes unruly.
    LVL 51

    Accepted Solution

    No.  The DLL call has to pass through an HTTP module or handler.  The web server is not designed to marshall function calls to DLL's.  You have to parse the URL and relay the function calls yourself.

    The URL you provided is not calling a DLL directly.  The HTTP protocol wasn't designed that way.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now