I have seen many articles in Internet to create a RESTful Web API by selecting the WebAPI project as project type. Is there any possibility that we can create the same using console application. If possible, how can it be hosted? How does an executable file gives us the URL to consume from the client application?
Yes, there is a possibility. but we need to flow some steps to achieve this.
we should use OwinSelfHost package for self hosting.
we should create as class file that inherits from ApiController.
install cors package for webapi application that is used for client to consume the application.
Hosting:
domain name or IP should be given where the service is hosted.
Reference Example
Related
I am still relatively new to writing API's and web services, so bear with me if I use incorrect terminology.
I want to know if it is possible to create an API in C# using nancyfx (or any other framework) or even just a simple web app and then set it up as a continually running web service using WampServer. I'm pretty new to Wamp, all I have done so far is create a few rudimentary pages with php; but I can't seem to find any information about running a web service with Wamp using a different back end language other than php.
WAMP is stand for Windows Apache MySQL PHP. As I can say, you can't run a C# web service with it base configuration. However, you actually don't need this. If you are on .net Core, there is a Kestrel web server. You can use it to serve your app. On a .net framework you have a HttpListener which can help you to implement self-hosted web service (for example, a windows service which hosts your application).
There are many other options, btw. Try google for some kind of "Hosting .net web application" or "Self-hosted .net web application"
I know how to create a restful web service using WCF. If i create the service as a "WCF Service Library" and implement it in a solution, how do i activate it, when it is not the main project?
I am using a N-tiered architecture. The webservice should have access to some layers below it, while clients from the outside should be able to call the webservice.
What is the best way to host a service in my case ? Windows Service? IIS ? Self-hosting?
Thanks guys
Thera are various options to host your wcf service , theory behind each option is detailed here
http://msdn.microsoft.com/en-us/library/ms730158.aspx
It looks like you don't have any hosting code , in that case hosting using iis is your best option as all other options require you to have some hosting code I.e. a main entry point.
For iis you just have to create a web application project as instructed in the iis hosting section in the following article
http://www.codeproject.com/Articles/150066/Create-Host-Self-Hosting-IIS-hosting-and-Consume-W
You can do this in two ways I think:
Visual Studio can host the service for you if you want (It should have set this up automatically)
Create a separate Console project where you host your WCF Service. Then change the solution to have multiple start-up projects, so that you can start both your app and the console for WCF. More info about self hosting here
You can configure a solution to start multiple projects. Here is the MSDN link for this.
I'm migrating an old Delphi application that I wrote into C#. The application is a datalogger that exposes logged data requests via a SOAP web service interface.
The web service is contained with the delphi graphical windows application, i.e. no need to run a web server like IIS, etc I just run the application and it's up and running under the hood.
I'm looking to do the same in my c# Windows form application, I can find loads of resources on writing web services that are ultimately hosted within IIS but am struggling to find a solution for a self contained web service within my application.
Does anyone have any suggestions or can point me towards any resources on this?
The web service does not neceserily have to be SOAP, REST is fine (in fact probably prefered).
Look into WCF Services.
Hosting and Consuming WCF Services
Hosting WCF services in a Windows Forms Application
The System.Web.Hosting namespace allows you to host ASP.Net pages without using IIS within your applications. I have never used it to host web services but I found a tutorial that seems to provide a guide on doing this-
http://msdn.microsoft.com/en-us/magazine/cc163879.aspx
If you're wanting to host a service inside your application, it's possible with the System.ServiceModel.ServiceHost class. You need to learn WCF first, but that at least answers your question to get you started. If you have any further questions, leave me a comment or two and I'll update my answer to accommodate your inquiries.
I have the following problem;
My console app is running on the server and all I want to do is control it over ASP.NET Web Service.
I added new ASP.NET Web Service project to my Solution where my main console app and added reference to it.
The problem is every time WebMethod calls function from console app, i get the nullreferenceexception. Even if I try to use static classes or singletons; every object is null, although my console app is running absolutely correctly.
Should I change some permisions setting or something?
Thank you for your time.
Based on your comments - your console app needs to expose API to administer it. Now this can be possible by using WCF Web Services where your console app needs to host the WCF Services. Controlling console app from ASP.NET web services would be difficult because ASP.NET web services would be hosted in different process/AppDomain (by IIS) - so they somehow need to talk console app process. This across process talk is possible in .NET using remoting or WCF. So its better to use directly WCF to provide web based API (instead of using ASP.NET web services).
Refer this article to start with creating simple WCF service and hosting it in console.
I have a question. How can i invoke a web service and get the result from a C# desktop application. I am making a desktop app and I want it to be able to connect to my online ASP.net web services. How is this possible?
In Solution Explorer, right-click your project node and select Add Service Reference.
Enter the URL where your service WSDL is located. This is usually the URL of the service itself.
This generates a strongly-typed proxy class in a new Services References folder in your project.
Write code in your desktop app to instantiate the proxy class and invoke methods on it. The rest works like magic. :)
AB Kolan was also correct, but Add Web Reference uses the old-style web services framework whereas Add Service References uses the new WCF stack. Important note: It is not required that the service itself use WCF for you to use WCF on the client side. WCF on the client is typically the best choice for any service, provided you can take a dependency on .NET 3.0 and above.
Add a Web Reference to the webservice in your Desktop App project reference. Doing so would generate a Proxy for the Webservice called Reference.cs
You can access your webservice using the proxy.
This is possible the same way that you access web services from any other type of application, be it an ASP.NET page, a class library or windows service.
For an explanatory tutorial on the subject, see Accessing a Web Service from a Desktop Application.
Will get help how to create a webservice and consume that service:
http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/
Thanks