IIS Proxy for a Windows Service hosted WCF Service - c#

I have a Windows Service that is exposing a WCF service thru a net.tcp channel.
Now I want this service to be exposed thru IIS, without being hosted in it. By doing that I will be able to maintain the state in the Windows Service, and I will benefit of the underlying IIS authentication and security.
Is it possible to do that just by using some configurations? Maybe a kind of proxy or passthrough?
UPDATE
Why am I doing that? A good question:
Some processes are running at a scheduled interval, asynchronously.
IIS is recycling AppPools and to trigger it, usually a web request should be issued, so that the AppPool is started.
I can't expose directly the service as a Web service in the Windows Service, because IIS is installed and binded to the IP Address that I want to use.
If I want to expose the service for many clients, using their own TLD, I don't want to have the same process running on each website (maybe for exclusive locks, or just for memory/CPU usage)
Perhaps this clarifies a little the need...

No you have to implement whole new layer in IIS. You will expose new WCF service which will call your WCF service hosted in Windows service. Is it really needed? Why don't you host the service in IIS directly or why don't you expose HTTP endpoint on your Windows service? What state do you maintain in Windows service?

Related

Communication between service and app - RESTful?

I am generating an app that would communicate with a service and show the service status in the taskbar. To do this communication, I am thinking of using RESTful WCF services. However, my question is, since REST would have to expose a port, is there a more efficient/secure way to do this? I am assuming the app and service will be on the same machine or possibly within the same LAN/ Active Directory domain.

WCF HTTP Activation using Srmp TransferProtocol

I've got a windows service calling a WCF web service using netMsmqBinding with the queueTransferProtocol set to Srmp.
All of this works great, except for when the application pool hosting the web service gets restarted or recycled.
The only way to get messages to send is by manually browsing to the URL, or using some http ping utility. Once the URL is activated the WCF web service starts to consume the incoming queue.
I had this problem before switching to Srmp, and I resolved it by installing the WCF Activation feature on the web server and naming the queue appropriately.
I've been forced to use Srmp due to firewall restrictions so port 80 or 443 are my only options.
There is a workaround here where I could set up a scheduled task to call each web service on schedule, but I would prefer a simpler more robust solution.
A full solution would be really nice, but I'm open to considering some other workarounds.
OK found the solution to this and was sure that I tried it before.
Install AppFabric 1.1 and set the web service application to auto start.
This resolved the problem.

WCF Service And Windows Service

I have a WCF service which serves as a remote file/folder browser. We also plan on having a Windows Service that will serve as 3 functions.
Windows Service will start the WCF service so it can do its job (part of the same project)
Windows Service will Upload some data to an SQL server every few minutes based on a timer + many other methods like this
WCF will Receive a request to run a method as requested by an asp.net client via WCF and then ask the windows service to run a method and return a result to WCF and pass back the result to ASP.net.
Item 3 is the problem. How is a windows service supposed to talk to a WCF Service (and Vice-Versa) service that both run on the same machine and are essentially the same application running as one. is it over WCF again?
Possibly i am going about this all wrong. Hopefully someone may be able to help
thanks
Damo
WCF Services may be hosted within Windows Services. See http://msdn.microsoft.com/en-us/library/ms750530.aspx. The specific example they give is for a console application, but the same concept applies.
When self hosting, you can eiter specifiy a type that will be instantiated when a client connects to the service , or you pass the instance that your clients will use when they hit the service. In either case, you can instantiate the same class or access the instance passed to ServiceHost to call methods on the service, though they would not go through the WCF pipeline. The WCF Service class can get a reference to the Windows Service class and access methods on that to allow for callbacks to occur without another trip through the WCF stack.
Alternatively, if you do not wish to self-host or your application uses WCF specific calls in the service, you can create a wcf client in the service in the same way as you would on a desktop application. Simply add a service reference as normal and use callbacks to hop back to the Windows Service code.
The first answer is correct.
I'll suggest also consider the following: if you don't have the windows service to host that wcf service, then go on with exposing new one in there. There are other options as well, but those are going lower level, so WCF is the easies and safest option. The same time - its quite elegant solution.

Two way communication using netTCPBinding

I am new to WCF (Just a day or 2). I am planning to make an application having Client/Server
WCF Service (On Server hosted as windows service):
Will invoke some commands using (Process.Start())
Will send some information from my database
Questions:
What WCF binding should I use? WsDualhttp or netTCP (Please elaborate if you can)
Does WCF works with SqlServer + EF 4.1
Server UI:
This will primarily will be used to
Start ot stop the above service
Change Address (localhost to [My Ip address]) and Port
Show status of service (Running or dead)
Questions:
How can I Change the address and port of my WCF service from this UI (it will be a different project and hence different config file).
Client App:
Used to issue commands to WCF service.
Get to know if the service is running or dead.
Receive status messages for task completion or faults.
Also, can the windows installer be combined to install ServerUI + WCF Service + Windows service?
WCF Service
Here are a couple links on choosing the right binding. Based on the scenario you're describing, I'd go with the netTCP.
C# - WCF - inter-process communication
Choosing the right WCF binding
WCF and SQL Server are independent of each other, so I wouldn't expect any problems using the Windows service to interact with your database.
I'd suggest reading up on how to start a process from a Windows service.
Server UI
I would suggest hosting another WCF service in your Windows service for interacting with your Server UI. You can use the netNamedPipeBinding since this communication channel will always be local, i.e., on the same box. So your Windows service will host two WCF services - one for the external communication with the client and one for the local communication with the configuration UI.
Installer
Yes, the Windows installer can be used, but that might be overkill for what you're describing. Of the Server UI, WCF Service, and Windows service, the only one that absolutely requires installation is the Windows service. The others could theoretically run simply by copying the assemblies to the target system. You might consider having the Windows service install itself via command line. That way you could get away with a self-extracting executable using software like WinZip. This might be less heavyweight than a formal install. If you go this route, have a look at the step-by-step here.
Ha a look at WCF duplex services:
http://msdn.microsoft.com/en-us/library/ms731064.aspx
Why do you want to have a interface to an windows service? And if you have access to IIS7 and WAS, I would recommend to use it instead of self-hosting in windows service.
Here is a good starting point for WCF Configuration Management:
http://msdn.microsoft.com/en-us/library/ff650534.aspx
Yes, you can use windows installer.
Cheers
--Jocke

Starting WCF Client in IIS

It is possible to have WCF Client that connects persistantly using duplex over net.tcp (netTcpBinding) from IIS?
i.e. the normal way would be to host it in a console app or as a windows service, my question is, could one use a shared hosting type of environment to run a WCF Client application.
i.e. the application isn't ever accessible from the outside, the application just connects to another service and consumes a remote WCF service over the internet.
If the ASP.NET app is the client, you could try loading the WCF Client into an Application or Session variable.
I've done something slightly similar with a System Timer and it worked a treat.

Categories

Resources