.net web service hosted within my application - c#

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.

Related

Communication between windows service and WPF with self-hosted owin web api

I need to make a WPF application running under a regular account and a windows service that will run under the admin account. The WPF application will call a service that then performs the required tasks.
What I'm dealing with is the way of communication between these two elements. Mostly I came across references to WCF and named pipes with which I do not have much experience.
So I thought I would create a self-hosting owin web api and use it instead of WCF.
I would therefore like to ask what are the disadvantages of such a solution. Is the use of a self-hosted web api suitable for such purposes, or I would rather use WCF named pipes.
Thanks for any advice :-)

How to use a WCF Service Library in a solution

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.

Creating C# windows service that is called by en event in the browser

I am a java developer and very new to C# and C++. I am trying to create a windows service in c# that another web application will call to close one of the projects in c++. I've created a dll file in c++ with a method to close the application.
I created a web service as specified in http://www.cjvandyk.com/blog/Articles/How-do-I--Create-a-Windows-Service-application-using-Visual-Studio-2010.aspx. However, I am not sure how to call this service from the web application.
Can someone advise me or refer me to some place where I can learn how to do this?
Not sure why you would want to go Windows service route. Your web application should be able to do everything on the server side.
If you have to use Windows service, you will need to expose some sort of service; e.g. wcf net.tcp service to accept calls for closing your app.
I would suggest you revisit your solution of using windows service.
You can try a software utility Application as Service by Eltima company. It lainchibg any application a s a service and offers different options. So If I've understood you right - it will help you.
http://download.cnet.com/Application-As-Service/3000-2094_4-10338474.html?tag=mncol;9

Hosting non web based application in IIS 7

I have heard that you can host non-web based applications in IIS7 similar to windows services. Basically I want a C# app that is just a process running all the time to perform a specific function. I want to create a process that connects to the database at an interval and does some work.
I would like this whole app to be housed inside IIS. Is this possible? Can you provide me with links and resources to get me started?
WCF services can be hosted in IIS. Abstractly, think of them as webservices. Really much more, than that, but it gives you the gist. More information:
How to: Host a WCF Service in IIS
Why we use wcf rather than web services
How To: Hosting a WCF Service in IIS
Take a look at AppFabric it's Microsofts Application Server
http://msdn.microsoft.com/en-us/windowsserver/ee695849.aspx
http://www.hanselman.com/blog/InstallingConfiguringAndUsingWindowsServerAppFabricAndTheVelocityMemoryCacheIn10Minutes.aspx

NullReferenceException while calling WebMethod

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.

Categories

Resources