How to invoke an executable desktop application from within an ASP.NET MVC application?
I have finished developing an executable desktop application to generate a fractal image based on the passed-in arguments. 开发者_如何学JAVAThe output type is JPEG.
Now I am developing a site under ASP.NET MVC 3. I want to use the executable from within my site.
Is it possible to use it as is without converting it to a class library and recompiling?
If you mean "to run on the user's machine", then not "as is" - you might want to look at Silverlight for that.
If you mean "to use at the server", then it will of course depend on how it operates (whether it prompts for input etc), and how it works (does it use GDI+, for example? that isn't recommended for use on web servers).
But sure; you can shell an exe with Process.Start
, or if it is a .NET exe you can either add a reference directly to the exe and use it as a library (if it has appropriate code)
There is also a way to run it in-process via AppDomain.ExecuteAssembly
- not sure this latter is a good idea on a web-server, though... especially if the exe talks to stdout
.
For getting the image back to the client, you would want this processing to happen (perhaps with caching) in a route that uses return File(...);
from MVC to simulate the image stream.
Use the system.Diagonstics.Process class to call the exe with a StartInfo object to pass the appropriate arguments.
精彩评论