Multiple Services Hosted under one Windows Service - wcf

I have two Services called TemplateService, TemplateReportService (both defined in one WCF Service Library) to be exposed to the client application.
Is it possible to host these two services under one Windows Service?
Thank you!

Yes, it is possible. Create two ServiceHost with different endpoints and open both of them when starting the windows service. You can even use the same port (if using net.tcp bindings) by enabling port sharing.

I personally hosted more than 80 services in one process by scanning a specific directory for assemblies with services inside (reflection). This was running on a quite powerful machine (8 cores, 16GB) with thousands of users. Shortly after finishing this I found this link: http://blogs.microsoft.co.il/blogs/alon/archive/2008/03/12/hosting-plug-in-wcf-services.aspx which is basicly doing the same but with a better separation between service hosts by using application domains. On a second try I would use this host.

Related

Deploy two versions of the same wcf service

I have created WCF service and its deployed on IIS& under WAS with specific port.binding is the NetTcpBindig.
After we implement another feature to the service and deploy again with separate URL.
but our client wants us to have same URL with two different ports for two different versions of the service.
What is the best option to achieve this task.?
You can host both versions with different ports in IIS. You will have to create two different sites, but I assume you're familiar with that.

Regarding wcf service hosting

i am new in wcf and started learning. i got one confusion like that i create a small wcf service and just do not host it in IIS,console apps or win service but from another apps i can add the service reference of svc file and found it is working. if wcf can work without hosting in any place like "IIS,console apps or win service " then why people would alway host wcf service in IIS,console apps or win service. can anyone tell me the reason.
people use IIS and windows services in general because they are simpler to setup and run more consistently. they can also be hosted more easily on servers where the services can be configured to start automatically, and as usually wcf is used as a server communication method it is usually this that you want to do.
hosting in console applications is generally easier to setup for simple examples for testing purposes, when you want to test your services locally.
Whilst hosting in applications as possible it's a less common scenario to use wcf to communicate between 2 applications on the same machine.
EDIT:
Your original question asked why people always talk about IIS, services etc. The point I was making was that usually wcf is used for web services, and is usually run on a server other than the local machine. Even though it can be used for inter process communication on the same machine this is not the most common use case. This is why you see a lot of examples using IIS and not too many hosting it in a Windows forms app.

Is is possible to 'relay' a WCF service from another server?

I've got a WCF service on a server on one side of a firewall. I need to access the service from many workstations on the other side of the firewall. The network guys insist that all holes through the firewall are one-to-one so at the mo, I'll have to set up every workstation one by one. There could be loads and it'll get tedious and be prone to errors.
Is it possible to set up a WCF server on this side of the firewall that can in some clever way just act as a proxy to the 'real' WCF service on the other side of the firewall? If so, could you point me to some reference material?
There is a new concept of a WCF Relay service being developed for the Windows Azure "cloud" computing space. That would allow you to create your scenario fairly easily - just host some bits of your service out in the cloud.
See these links for more information:
WCF services hosted on Windows Azure
Software in the cloud: the Relay service
.NET ServiceBus: Hands-On with Relays
or search Google for "WCF Relay Service". There are also a number of new bindings specifically for these WCF scenarios.
Hope this helps.
Marc
UPDATE:
WCF v4 - to be released with .NET 4.0 later this year (2009) will include a RoutingService class which can be used in scenarios like this.
See more info about the WCF4 routing service here:
Content based routing in WCF 4
Routing messages in WCF 4.0
A developer's introduction to WCF .NET 4 Beta 1
I have a few suggestions, maybe one would work in your case:
Place the WCF service outside the firewall. If the WCF service needs to talk to the database, open the database port for the IP address of the machine running the WCF service.
Program or use code generation to create a WCF service that is simply a pass through layer
There may be some functionality in your firewall that allows you to publish an end point

How to develop a WCF Service to automatically manage other related WCF services hosted as Window Service?

Kindly help me in architecting a solution which is required for my ongoing project.
I have developed some WCF Services hosted as windows services which I did and working fine so far. Now I am asked to develop a master WCF type of service which should be intelligent enough to manage all other WCF service for possible corruption/errors and can repair them and restart.
Thanks in advance.
As we have written a custom host and took us years to make it a real application server, I will share some of the challenges that we had. Creating a custom host that manages WCF services as an NT service is a very challenging task if you want to manage all of the details and treat the NT service as a real service host. The challenges start from managing multiple Appdomains ( one for each Service ), managing the statuses of the services, startup times, deployments from the IDE and the worst of all is activation. Have you considered how to implement that? If you do not have this feature, it means that all of your services will be active and in memory at all times. IIS and Appfabric do that very well and trust me , it is noty easy to implement. The other part that was challenging was a UI to manage this host and offcourse a UI that can manage multiple hosts ( NT services running on different boxes ). Do you need a discovery proxy implementation? And at last how about if you want to manage services running in your custom host , IIS and App fabric the same way?
Think about before doing such an implementation because the scope may crypt on you as you do it.
I do something similar here.
Create a Dictionary<key, ApplicationDomain> collection into your main program
Key: something unique for each application domain, like a Guid or a System.Type.
That ApplicationDomain class exposes a internal property to access your AppDomain proxy (that which inherits a MarshallByRef class)
Load your WCF host into main program, so you'll get access to that collection
Every time your service get some access, you just need to take that key, access your proxy and do anything you want within your service hoster.
Keypoint: Your service must have access to all your service hosts.

Running Multiple Services Over net.pipe in WCF

I am building a distributed application that will require 6 different services. I will have to demo the application on my XP laptop using Visual Studio 2008.
Is it possible to run multiple services on localhost at the same time, all using net.pipe?
For example:
net.pipe://localhost/DirectoryService
net.pipe://localhost/MathService
If not, is there any other way to host these WCF services without using IIS/webdev server? net.tcp? Something else?
Another thing you should know about net.pipe addresses is that you are providing a URN, not a URL. net.pipe is an in-memory implementation and the "address" you are specifying can be anything.
net.pipe://IHateCats
net.pipe://NamedPipes/Are/Fast
These will all work, regardless of any other factor. It's just the unique identifier for that named pipe. The network stack is not involved with this form of communication.
Yes, providing the binding addresses are unique. The two examples you've shown will work fine with the net.pipe binding.
Keep in mind the net.pipe binding will only work on the local machine. If you want your services to be accessible from remote machines, you'll need to use a different binding, such as net.tcp. That said, net.pipe is the recommended binding to use if your services run on the localhost because it is more efficient that the other bindings.
You can use HTTP as a service end point without IIS, take a look at the ServiceHost class. That's what I use for local WCF tesing and it works very well.