WCF hosted in windows service errors - windows

I have a WCF in VB which is to be hosted in a Windows Service. I managed the install program so the service actually installs. But, when I try to start the service, I get the following error:
The service on Local Computer started
and then stopped. Some services stop
automatically if they have no work to
do, for example, the Performance Logs
and Alerts service.
Cheking the Event Viewer gives me the following:
Service cannot be started.
System.ArgumentException: ServiceHost
only supports class service types.
at
System.ServiceModel.Description.ServiceDescription.GetService(Type
serviceType)
at
System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2&
implementedContracts).........
Anybody have any ideas what's going on? Thanks!

The ServiceHost constructor must be concrete implementation of service contract.
It sounds like you are passing in the Interface rather than the service implementation.

svh = new ServiceHost(typeof(MCWCFService.MCManagementService));
svh.AddServiceEndpoint(
typeof(MCWCFService.IMCManagementService),
new NetTcpBinding(),
"net.tcp://192.168.0.2:8011");
svh.Open();
When creating the ServiceHost use the Class name - in the above it is MCManagementService. In the endpoint, use the interface - in the above it is IMCManagementService.

Related

How to call an already running windows service?

Is there anyway to call a windows service that's already running or a process to get info? What my goal is to find out if my windows service is an infinite loop or dead lock and see if it responds. So I want to be able to pass an argument from another program to a windows service and want it to to return a string or number. Is this possible? I can change the windows service to accommodate this. I am thinking of an event or something.
Note: I am not supposed to have the service write to a file or database.
You can host a WCF service in your Windows Service which you could call to get status information.
Here are a couple of links on doing that:
Can I host a WCF Service in a windows service?
How to: Host a WCF Service in a Managed Windows Service

Communication between wcf and windows service?

I have a situation where I want to establish communication between WCF service and Windows service.
I want to pass messages from the Windows service to the WCF service
I want to send array list from the Windows service to the WCF service
How can I achieve this?
Edit:WCF is hosted on IIS.
if any code snippets it would very helpfull.
Thanks in advance
loke
Yes you can, just add a reference to your wcf service in your windows service.
In Visual Studio right-click your project and choose Add Service Reference. Enter your WCF service address and choose namespace name. Visual Studio will download WSDL from you web service and create proxy for you.
Then just create proxy object and call web service methods:
YourNamespace.YourServiceClient client = new YourNamespace.YourServiceClient();
client.Open();
client.YourOperation();
client.Close();

Need a step-by-step WCF as Windows Service

I'm trying to find a (good) step-by-step example of creating a WCF and hosting it as a Windows Service (with installer). I'm using VS2010 and have a simple WCF with 1 function (just returns 'Hello').
Please don't Google and post; I'm looking for a resource someone has actually used. Most of the Googling I've done hasn't turned up much for what I'm trying to do.
I just want to take my WCF library, and find a way to install it as a Window Service. I've done it in 2008, but 2010 is... Different.
For future reference - for anyone else looking at this thread:
Here is the best example I've found for what this question was looking for:
CodeProject: WCF Service with Windows Service Hosting, consumed from C# App!
This link mentioned above shows how to consume the WCF service, but with a lot of other stuff to wade through:
MSDN: How to: Host a WCF Service in a Managed Windows Service!
This second link above is good for creating the WCF service, but not for consuming it:
MSDN: Hosting and Consuming WCF Services!
I rarely find MSDN articles that I like :-)
You just need to host the wcf contract class in your onstart method of service calling ServiceHost host = new ServiceHost(YourClass) and in onclose method of your service you need call host.close(). The hosting option depends on what type of clients you want to talk to if you want to talk to pure html clients using REST you need to host your service in WebServiceHost and the binding you need to use in that case is webHttpBinding.
I have followed the following example and was able to create windows service hosted wcf and im sure this what you are looking for link
I did not find any difference in creating wcf service in vs2008 and vs2010.
What type of clients do you want to talk and which protocols do you want to support. This all defines your configuration.
What I've used when I use WCF in a Windows Service is Topshelf as a Windows service framework and a modified version of this Code Project code to dynamically host, install and run WCF services.
Topshelf makes it very easy to develop and debug because it can be run as a console application. Being able to dynamically update WCF service libraries without stopping the Windows service is just cool. ;)

How to access web service on port other than 80 in vs2008/2010

I tried searching the net, also tried some workarounds I found (like manually executing wsdl.exe) but still I can't access a remote web service running on a port different than 80 (say 1234).
When from Visual Studio 2008 OR 2010 I add a web reference using a url like http://192.168.1.2:1234/WebServices/Test.asmx, the service is found but when I press Continue, VS is unable to create the proxy classes and gives me an error saying that http://192.168.1.2/WebServices/Test.asmx (notice the missing port) was unable to return anything. Is there something I can do apart from creating the web service localy, creating the proxy classes and then manually changing the url?
Thanks in advance!
You're supposed to set the Url property on the web service proxy class.

Writing Windows service in WCF

I want to write windows service in wcf After searching a lot I only found were tutorials of writing webservice in wcf not windows service.
Can any one please provide a link to any tutorial which explains how to write windows service in WCF
Windows services are executables. WCF applications are, generally, web services, exposed over a URI. You can host a WCF application within a windows service, not the other way around.
To create a Windows service in C#, follow the step-by-step here. To make your Windows service WCF-enabled, if you will, create the System.ServiceModel.ServiceHost instance that will host your WCF service inside the OnStart() callback.
Good answers all of them. Just a quick note... implement your WCF service in a class library (dll) so you can then host it anywhere you like (IIS, Console App, or Windows Service).
I'd recommend starting from a console application, after your service works as expected, create a Windows Service, add a reference to you library and start the service (WCF) from there (Windows Service)
Edit: I just assumed you meant create a WCF service hosted as a Windows Service, if that's not the case please ignore my answer.
Create your WCF service as normal, create a Windows Service and then use ServiceHost to self-host the WCF service in your Windows Service. See this MSDN page for more information about self-hosting WCF services.

Resources