C# as web application - c#

I'm looking for advice on the best way to accomplish running my C# application as a web app. My app takes a file and some configuration settings as input, it runs some scripts against the file, then outputs a new file.
I want to be able to run this as a web service so that it can be accessed from any OS, by keeping the .exe and referenced DLLs on the backend.
Is there any way to accomplish this? I know I have an option to spin up a virtual server and use RDP, but I want to make it a native web experience.
Is WCF the solution?
XAML?
Does Microsoft have a solution to take an .exe and run it on an IIS web server?
Thank you!

You can do this pretty easily with just a simple web application; you don't need to do much of anything special. Simply invoke your exe with the Process class:
Process myApp = new Process();
myApp.StartInfo.FileName = ConfigurationManager.AppSettings["myAppLocation"];
myApp.StartInfo.CreateNoWindow = true;
myApp.Start();
myApp.WaitForExit();
// Open file and read it
// Additional Info at http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
However, the better choice would simply be to extract that code from your EXE (you likely have the code somewhere) and introduce that as a Class Library for your web project to consume.

Unless there is a reason you absolutely need to keep your existing app as an .exe called in the backend, the easiest solution is to integrate your C# code into a simple ASP.NET web app. You can reference existing DLLs from within the web application to use tem on the server side. Check out a tutorial on making a simple ASP/NET web app, such as:
http://www.kirupa.com/net/helloWorld.htm
Just add an html input field to allow a user to upload the file, and make a download link for the output file.

wcf is a service but not executable thing, you may have a look in Browser WPF application, or Silverlight...
Between both of them , silverlight is highly recommended while it is more heterogeneity. bwpf is easier because just do as what you do when you creating a wpf application but only able to run under IE
http://silverlight.net/ the loading thing is build with silverlight and it is running under IIS ONLY
the browser wpf is your exe and dll thing...

Related

What .NET project/service to use for a background app that runs all the time?

I have to make a program that watches a location on a computer for files and then converts them when new files get put into a specific folder.
Now my question is what kind of Project would be most appropriate for this?
Is ASP.NET MVC Web Application a good choice or would I be better of doing a Windows Service or WCF Service or even Console App?
My app needs to run on the same server as another MVC app already runs, and I need to access some database to keep track of what files I have converted.
You could utilize Windows task scheduler to periodically run an exe file. In this case the project would be a console app.
A better solution would be to use Windows service. See comments from David & as.if.i.code (tnx btw, you learn something new every day :)

How can use scheduled task for live environment in mvc, c#

I'm building a website using mvc,c#. In my case I use xml files to bind data.
xml file is download from the web service.it updates once a day.so I have to update the xml file (web service gets more time to load data) according to the web service. What I wrote a method that will run on scheduled time each day.but most says it will not work fine in live environment. then I searched .most says to write console application.but I do not have idea how to use it with my project, and in live environment.what should I suppose to do.hope your help with this.
I'd write a console application and use the built in Windows Scheduler to activate it. Windows Scheduler will deal with failure actions (logging, retry etc).

Web-Update class in WinForms application

I have build an C# Winforms application which will need regular updates and patches in the future. To ease the update process for the users of my app I'd like to build an web-update class that looks for an update on my site.
What would be the most secure and reliable way to implement such a class, considering:
The site is build in PHP / Joomla
I haven't the foggiest idea how to program in PHP
All webserver directories are read-only by default (and only writeable by an FTP account I own)
The first and so far only idea that comes up to me is to create a file on my webserver that'll never be renamed, and in it I'll define the location of the latest version and number of it. The app will then be able to download the update from that path using the WebClient class.
However, if there's anyone with a better update-class idea that doesn't require an asp.net webserver nor webservices (already tried and failed on that one), I'll be grateful.
Edit:
I've tried the ClickOnce solution suggested by Gabriel McAdams, but on application startup I experience a "ClickOnce launch utility has stopped working" crash. So I'm again looking for a solution to update an application. For the moment, the answer of Kristian Damian is the most suitable.
I would look into ClickOnce Deployment.
Here is some of the text from that page:
ClickOnce deployment allows you to publish Windows-based applications to a Web server or network file share for simplified installation. Visual Studio provides full support for publishing and updating applications deployed with ClickOnce.
Maybe this link can help you:
http://themech.net/2008/05/adding-check-for-update-option-in-csharp/
I developed a Windows application in C# that does updates automatically over the Internet. After much grief, mainly because at that time I had very little experinece with Web development, I purchased a product that made it easy to update the application. If it is OK with StackOverFlow and you are interested, I can give you the URL.

Embedding .net remoting program in WEB

So, here is a deal.
I have client-server application(dotNet remoting). Client side has few trackbars, checkboxes, buttons and picturebox. Server is a console application and does only calculation from client. Client's picturebox make some visualisation of calculation in picturebox. All calulations and relative classes are in dll file.
Now I have to embed client application in web site. All kind of technologies are accepted, but I want to minimize forces applied to embedding. So, what is the best way to do embedding?
What about SilverLight or Flash?
You need to create a web site that accesses your remoting server and renders output as HTML. I seriously doubt that you will be able to get remoting working inside a browser environment, even using something like Silverlight.
If you don't want to use a full blown web server then use the .net class HttpListener in your server application to create an embedded web server.
If you want to take a C# application and access it through a web server, look into iHttpHandler. You need to compile to a DLL, and configure your IIS server.
There are a number of tutorials on the web. One is: http://www.codeproject.com/KB/aspnet/CustomImageHandler.aspx

Thoughts about using Silverlight In Desktop Apps?

To summarize, as we all know,
a) Silverlight is expected to be hosted by a browser, and runs in an isolated sandbox so that there won’t be any security issues
Silverlight don’t have direct access
to the file system, other than the
isolated storage area
There is no
direct way to open common dialog
boxes like File Save in Silverlight (Though Opendialog box is supported).
b) Silverlight can’t access local resources like a printer
What are the ways to go beyond the sandbox, so that I can host a Silverlight application locally, to read files and save them back if required, to hand over data to a printer, and so on..
Update:
Is full WPF is not an option for me? No. I'm also interested in a cross platform solution - for instance, you could host Silverlight in Mono Web browser control, so that you can run it virtually anywhere.
The idea is to re-use the same application that I'm building for web in my desktop as well, by providing separation of concerns at some areas - like persistence, resource access etc.
Scenarios:
1- Some kind of gadget container, with access to local resources.
2 - A desktop Silver light based media application
Update:
I just did a POC to enable me to access printer and save files locally, of course through a shell where I'm hosting my Silverlight application. If you wan't you can have a look at the post here in my blog
Two ways I can think about is,
Create a "Shell"
Host the HTML Page with Silverlight, in a Winforms desktop application, using a web browser control, and communicate to and fro using HTML DOM. Then I can request the hosted shell to do things like printing. See details here
Mono also has a web browser control - based on FireFox XULRunner instead of IE - not yet succeeded in loading Silverlight inside that. Another option might be using Webkit.
Embed a web server
Embed a light weight web server with in the Host application, and handle requests to perform such operations. You can probably define a protocol on top of HTTP for things like saving to a local folder, sending data to print etc.
Is a full WPF application not an option for your situation?
As you probably know Silverlight uses a subset of WPF so you may be able to change your application relatively easy.
A wpf app would be easier than having a web server etc bundled within your application.
You wont in the foreseeable future be able to have access to resources such as printer and files (apart from isolated storage) through Silverlight as you know.
You could have a seperate part of your app to upload files to the webserver then read these in your silverlight app from a service.
Depending on your printing requirements (e.g. if you just want to send everything to an office printer) you could send the informaton you wanted printed to a service that will then print it for you. However I am guessing you want each client machine to be able to print in which case this wont work for you.
I am attempting to also reuse a codebase for both desktop and silverlight. There are two options that I know of in addition to the ones mentioned
If you directly reference (instead of a project reference) a silverlight dll from a normal project, it should work. This would let you reference a silverlight dll for both projects.
Have two project files (one wpf, one silverlight) that point to the same set of files. You might have to have to use a few compiler flags here and there, but this should let you use the same files for both.

Categories

Resources