[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1206
  • Last Modified:

How to call a DLL via URL

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]
0
itbox
Asked:
itbox
  • 2
1 Solution
 
Ted BouskillSenior Software DeveloperCommented:
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.
0
 
itboxAuthor Commented:
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: www.myurl.com/superawesomeimageresizer.dll?newname=foo.jpg&width=100&height=100

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: www.myurl.com/imageresize.aspx?version=1&... 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.
0
 
Ted BouskillSenior Software DeveloperCommented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now