WCF service can be hosted both in IIS and in Windows service. What are differences? Is there any benefit hosting in Windows service than IIS?
Check out the documentation: https://msdn.microsoft.com/en-us/library/ms730158%28v=vs.110%29.aspx
It is awesome!
And the answer to your questions depends on what kind of application you are building and other requirements on the application/environment...!
Here are some differences (Features of IIS.. Copied from the link provided by #Jocke).
You lose all of the features of IIS (logging, application pool scaling, throttling/config of your site, etc.)...
You have to build every single feature that you want yourself HttpContext?
You lose that since ASP.NET provides that for you. So, I could see that making things like authentication much harder WebDeploy?
IIS has some nice specific features in 8 about handling requests and warming up the service (self-hosted does not)
IIS has the ability to run multiple concurrent sites with applications and virtual directories to advanced topics like load balancing and remote deployments.
If your WCF serivce is self-contained, like a data service, just host it in IIS. Drawback: you'll have to install and configure IIS.
If your WCF service is more of an API or IPC mechanism, used to let other applications talk to your application, it makes more sense to let your application self-host the WCF service, and for that a Windows Service usually is the more sensible approach. Drawbacks: you'll have to install your application as Windows Service, and configure that your application may listen on its configured port.
Please note that self-hosting is not constrained to Windows Services.
Related
I want to know why we should use Webapi SelfHosted and where it is useful?
Let say we have a console application and selfhosted webapi what is the benefit?
The main benefit is that you do not have to set up IIS and websites when you deploy it. This way, you can simplify the deployment of the service and make it easier for administrators that are not experienced with IIS to install it. Typically, you would not use a Console application for self-hosting an API in a real-world-scenario, but a Windows service that runs whenever the computer is running - without requiring a user to be logged on.
In a less common scenario, you could use a self-hosted Web API for inter-process communication. If you want to exchange data between some processes either on the same or on separate machines, you could host a Web API in the application that provides the data and access it from another one.
I have a couple of services, where one of them needs to be a singleton service. The other services connect to this singleton service and the singleton service in turn makes calls back in to the instances of the other services.
My question: is it safe to move this scenario into IIS so I can make use of the new Windows Server Appfabric features? I'm not sure how IIS handles instance management.
I would go for IIS as well because compared to other hosting mechanisms you get a lot features for free:
process life-cycle management,
process recycling,
shared hosting,
on-demand activation,
health monitoring
IIS should not be problem in your scenario. If it already works with self hosting it should also work in IIS. You only need to be aware of some IIS management settings which control AppPool recycling etc.
Hosting in IIS is the way forward definitely. Especially if you have AppFabric installed as you mentioned.
All,
I have been writting Windows Services for a while in C# deriving from ServiceBase.
So far my services are hosted in servers where they usually listen to message queues and process messages.
Is there a new way of creating such services in WCF ?
Thanks,
MK
Yes. Check out Windows Process Activation Services.
From what I understand, it's very much like how you used to host remoting objects under IIS, but with WAS, you don't need to involve the whole huge IIS stack like you used to.
Microsoft Message Queuing would seem to be what you'd want though there are some offshoots like BizTalk Server that may use similar stuff. Just to toss out an idea or two.
I've started using an open source project called TopShelf to easily create applications that run as either a Windows Service or a console app for debugging.
I've also been hearing a lot about Windows Server App Fabric. Here is a quick blurb from the App Fabric white paper.
AppFabric Hosting Services (originally code-named “Dublin”) doesn’t create some entirely new hosting infrastructure. Instead, it builds on what’s already provided by Internet Information Services (IIS) and Windows Process Activation Service (WAS). On this foundation, AppFabric Hosting Services adds extra capabilities for running and managing WCF services, including workflow services. Figure 7 illustrates this idea.
Windows App Fabric Home
I am going to be coding up a windows service to add users to a computer (users with no rights, ie just for authentication). (As a side note, I plan to use this method.)
I want to be able to call this windows service from another computer.
How is this done? Is this a tall order? Would I be better off just creating a Web Service and hosting it in IIS?
I have some WCF services hosted in IIS on the calling computer (they will do the calling to the proposed windows service). I have found that Hosting in IIS is somewhat problematic, so I would rather not have a second IIS instance to manage unless I need to.
(I will be using Visual Studio 2008 SP1, C# and Windows Server 2003 (for both caller and service host).
Thanks for the help
If you are thinking of hosting a web service in IIS just to communicate with an NT-service on that same machine, that is definitely more trouble than it is worth in this case.
As other answers have indicated you can make a WCF service with the operations you need and host that within the same NT-service that you want to interact with. You can easily secure this with certificates, or user accounts to make sure it is only controlled by the right people/machines.
If you need to control the NT-service itself, there are existing programs such as sc.exe to start, stop, configure, or query the status of your NT-service remotely.
However, you may want to consider seeking a solution without the overhead of creating an custom NT-service and a custom WCF service to interact with it. If you do, the Net User commands (sorry no link - new user limitation) or the AddUsers (see kb 199878/en-us) utility may be sufficient. If your remote "controller" can invoke these commands directly against the target machine you may not have to create any custom software address this need. Additionally you would have less software to maintain and administer on the target machine. You would just be using the built-in OS capabilities and admin utilities.
Finally, you will need to think about the security aspect, NT-services and IIS are usually run under very restricted accounts, many auditors would flip-out over any service running with sufficient permission to create or modify users locally, and especially on other machines. You'll want to make sure that the service could never be used to create users that do have more than the "authenticate" permission you indicated.
Edit: The net user command may not work against another machine's local users, but check out. pspasswd that along with PsExec to create users, should do what you need remotely.
Simply host a WCF service in the Windows Service. You'll then be able to call it remotely.
You can host a WCF service inside a Windows service. Take a look at the TCP binding (NetTcpBinding class). Both client and server will have to use WCF, but that doesn't sound like it will be an issue with your implementation.
Also, the section entitled "Hosting in Windows Services" in this MSDN article provides a walk-through of the process
If the windows service publishes a remoting interface then it can be accessed via that remoting interface.
Otherwise it's the same as accessing any other process running on a remote machine except that there may be some tools (e.g., sc) with built in support for executing against a remote machine (barring firewall complications).
Any IPC mechanisms applies; sockets, web services, remoting, etc...
You could expose a WCF service directly from your windows service. When you start up your windows service, in addition to spinning up any other background processes, you could create an instance of ServiceHost<T> for your service implementation. This would allow you to not only provide WCF access, but also avoid the extra instance of IIS like you requested, and provide TCP, Named Pipes, and WsHttp endpoints. This should give you some nice flexibility in the performance tuning arena, since it sounds like this service will be consumed internally on your network, rather than externally.
You could create a WCF service which will talk to your Windows service on the remote box. Host the WCF component in IIS (or however you'd like so that you can communicate with it) and then call the WCF component from your remote machine.
What are the various methods of hosting a WCF service?
There are four common ways, all of which are outlined nicely on MSDN: Hosting WCF Services.
Hosting in IIS.
Hosting in WAS.
Hosting in a Windows service.
Hosting in an application (aka "self-hosting").
For right now, everything that's been said is correct.
Hosting in IIS6 only support HTTP protocols and "on-demand" activation
Hosting in IIS7 / WAS (only on Vista / Server 2008 and up) supports all protocols and "on-demand" activation
Self-Hosting in a console app or Windows service supports all protocols, but doesn't support on-demand activation (e.g. your service must be up and running all the time, it cannot be magically activated when a request comes in)
What's not been mentioned is what the .NET 4.0 wave later this year (2009) will offer - there's a new add-on server component called Dublin which is said to offer a rich and managed hosting environment for both WCF services as well as WF workflows.
Marc
You can host it in an IIS application or in your own executable. Typically the executable would be a windows service application.
Any Windows process can be used to host a WCF service. There are practically no restrictions on this - a process can host multiple WCF services and the same WCF service type can be hosted across multiple processes simultaneously.
From Juval Lowy's book Programming WCF Services, hosting can be provided by
Microsoft Internet Information Server (IIS)
Self-hosting within a Windows Forms application, Windows service, or console app
Windows Activation Service (WAS)