Writing an windows service using the .net framework (not dotnetcore) with c# that needs a web interface to manage it. No IIS or anything else installed other than the app to serve html files for the web interface - so need a webserver to serve static html files.
The static html file that will be served will call web api methods via javascript to query data and manage the internals of the service.
Already using self hosted web api with HttpSelfHostServer to write methods that can be queried via javascript using ApiController.
To serve the static html file I could do the following:
Use HttpListener to serve the static html file
Write a method in a ApiController that returns FileContent using HttpSelfHostServer and create a "index.html" route
Since they are just static files I could just HttpSelfHostServer and have a webapi method return the contents of the html file.
Not sure if there is a benefit of one over the other in this case. Any thoughts?
Related
I have a frontend website made using Angular that accepts an uploaded file. I want to be able to save this file into the web server the website is being hosted on. I would prefer to only use Angular to do this, but I can also accept if there is a way to do it in ASP.Net Web API backend.
You can download the webserver file using angular.
Try the below example...
downloadFile() {
window.open("http://www.africau.edu/images/default/sample.pdf") //your URL
}
I created some chrome extension that detects a file download event and cancel the download, and gets the download link. Sends the link to myserver.
I want to create a server that recive link to download, download the file, do some manipulation on the file and sends the file back to client.
All the time I developed client side apps (Mainly with c#), and I don't know what to choose for the server side, WCF App or Web API (or something else). the server can be inside the organisation or remote.
What do you think should I pick? any suggestions?
It seems that creating Restful-style services may be more appropriate for this scenario.
You know, both WCF and Asp.net WebAPI can create Restful-style services. WCF could take advantage of the Webhttpbinding to create it.
As for handling file uploads and downloads, I don't think there is any difference between the two techniques. Perhaps the services created by Asp.net WebAPI are a little more mature, such as the ability to deal with form-data stream (multipart/form-data) directly. While WCF service could not directly process the form-data stream.
Here is an example of an upload and download in Asp.net WebAPI.
https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/sending-html-form-data-part-2
How to return a file (FileContentResult) in ASP.NET WebAPI
Feel free to let me know if there is anything I can help with.
Is it possible to create a separated class library project as the web service of an ASP.NET MVC project? (Actually, I want to have an MVC Project and a class library project as its web service to call methods by using Ajax in the web project)
I tried this as the URL of ajax request but Ajax couldn't find it: ('Mine' and 'Service' are namespaces; 'UserService' is the name of the class, and the 'SignUpUser' is the method I want to call:
url: "Mine.Service.UserService/SignUpUser"
There is a much better way to call your web service.
You can use the WEB API in ASP.NET to expose your services and data rather than creating separated class library to call your web service
How can I call / use web API that supports SOAP and REST? I want to write a program in C# that will use this web API. I didn't get much information on the internet. So far, I have created C# project and added the web service reference (WSDL) to my program. Now how can I use the web API. How to send request or receive response? Can you please refer me some good tutorials ?
The HttpClient class is a good starting point. Also there is the EasyHttp library.
Code sample HttpClient: http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
Introduction to EasyHttp: http://devlicio.us/blogs/hadi_hariri/archive/2011/01/16/easyhttp.aspx
Adding web service reference creates client classes that can be used to communicate with web service. All created classes will be in new namespace, You have to look for client proxy class (full name depends on WebService name). Create instance of this class. Calling its methods will call WebService. Here you can read about using Web Services in C#
I recently got a requirement to develop a new web service, and I'm not entirely sure how to approach it.
I'm familiar with normal WCF web services, where the url is something like
http://server/site/Service.svc/SomeMethod
that you can post XML/JSON to.
The new service is supposed to accept an HTML file post, where the content type is
multipart/form-data
From what I understand, the form contains fields, one of which contains a bunch of XML data which I want to parse. I will then respond by posting my own similar html file to a remote location.
I'm not completely sure how to begin with this.
A WCF Service of some kind?
ASMX?
Or even an actual ASPX page that the client will post to?
You can use an .asmx file to create a web service and can use it through aspx pages