.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

WCF hosted in a Windows Service, how to make calls to the WCF service from within the service host

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :WCF

I have a Windows service that I converted to a WCF service that I want to host in a Windows Service.  I need to do some specific tasks in the OnStart() and OnStop() just like I did when it was just a Windows service.  My original Windows service OnStart() is where I create the main worker thread.  So how do I make a call into my WCF service from within the hosting service? For example in the hosting service's OnStart() I do a host.Open() then I need to call a method in my WCF service but how?



ServiceHost host =

View Complete Post

More Related Resource Links

Windows Services: New Base Classes in .NET Make Writing a Windows Service Easy


Windows services are applications that run outside of any particular user context in Windows NT, Windows 2000, or Windows XP. The creation of services used to require expert coding skills and generally required C or C++. Visual Studio .NET now makes it easy for you to create a Windows service, whether you're writing code in C++, C#, or Visual Basic. You can also write a Windows service in any other language that targets the common language runtime. This article walks you through the creation of a useful Windows service, then demonstrates how to install, test, and debug the service.

Ken Getz

MSDN Magazine December 2001

Question about WCF Service hosted in Windows Service

Hi, I have little experience with WCF and working on a projet that requires WCF Service instance to run 24x7. After searching for a solution and reading about WCF, I think if I host it under Windows Service I can have a single instance of WCF Service running 24x7. Is this correct? I just successfully ran the MSDN sample project that hosts CalculatorService in Windows Service. I realized that Windows Service cannot communicate with WCF Service it is hosting (I do not have any experience with writing Windows Service). I wrote a test function (public) in Windows Service and tried to call it from WCF Service but it did not appear in the Intellisense list. Is my assumption correct or is there a way to establish communication between Windows Service and its hosted WCF Service? Thanks. kr

How to use single windows service to host multiple WCF Services instances (Each instance of WCF is i

How to use single windows service to host multiple WCF Services. I have a mutiple instance of same WCF service in different folder, each instance has unique service name and port. WCFService has reference to Reg-Free COM Reference, i have Native.WCFService.manifest in each folder. Ex: WCFService1 is in "C:\WCFService01\WCFService.dll, Native.OCWCFService.manifest, OCWCFService.dll.config WCFService2 is in "C:\WCFService02\WCFService.dll, Native.OCWCFService.manifest, OCWCFService.dll.config Now i need host above services from single Windows Service. I am trying to create AppDomain for each above WCFService Instance from Windows Service and then host. Its working if i register COM dll in the server using regsvr32, but when i un register COM dll, i am getting unable to load COM component .... This looks like AppDomain is not loading COM DLL and Manifest files. Its looks strange but we need it in this way because we have production and test environment in the same server. Everything works fine if create a seperate Windows Service for each WCFService Instance, but my manager wants single Windows Service :). Any help whould be really appreciated.  ravi kumar reddy

Bi directional service calls with "n to 1" and "1 to n" servers has host

Hey there.   I've been tasked to find out how to do the following for our company:   We have our ERP (MS Navision) exposed to the net to take orders. So far so good. Now management wants me to integrate our system with 3 other ERPs and 100s to 1000s of clients all having their own networks and sql servers which are completely outside of our "control".   Here's where I have a big problem.  In the "normal" way of things, each of the ERP, installed on each of our 100[0]s of big clients would be calling my services to process orders and whatnot.   However, the first step of our system is to do a search and display inventory.  We want to have complete control has this system is a new flagship product and we can't let other companies duplicate it.  The big sticking points for our clients is that they want us to show THEIR inventory on OUR site.  This happens after a login, but before their servers ever call mine. That means that I have to query their webservices first... 100[0]s of different servers (1 per client allowed on the system).   Now if we had only 2-5 clients I'd know what to do, but how can I have a scalable setup with 100s and possibly 5000+ different clients? 

Suspend / Resume Instances within Workflow Service Host (in Windows Service)

We are hosting WF 4 worklfow instances within a Windows Service that uses the Workflow Service host container.   On the Windows Service OnStart we start the workflow service host (w/ multiple WCF endpoints such as start workflow instance, cancel workflow instance, poll workflow instance status, etc.) and these endpoints create or work on one or more long running workflow instances.     My question is, if a user attempts to stop the Windows Service while workflow instance(s) are running, what is the best way to manage this scenario.   Our inclination is to persist these workflows (using sql persistence) and then on the next start of the Windows Service, resume these workflow instances and allow them to continue to completion.    In OnStart, we have a handle to the Workflow Service host.    How can we iterate through all the active workflow instances in OnStop and then in OnStart, resume these after the workflow service host is opened and running?   Are there are any methods of managing this scenario?    Thanks

TCP Error Code 10060 when attempting to access WCF Service hosted by WIndows Service from client run


Hello all,

We have a Framework 3.5 WCF Service which is in turn hosted in a Windows Service using Net.Tcp Binding. SvcUtil is used to generate the proxy which is used instead of a service reference in the client code. We are also using Tcp Port Sharing. The endpoint address is net.tcp://HostMachineName/MyServicePath. The service logs to the Event log and everything works perfectly on the same machine.

When attempting to run the client from a different machine we are getting TCP Error Code 10060 errors. Below is the error message:

System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://HostMachineName/MyServicePath. The connection attempt lasted for a time span of 00:00:20.8592415. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.22.333.444:808.  ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.22.333.444:808... The IP Address displayed was the correct IP Address for the HostComputerName.

Has anyone encountered this problem? Also, client specs say no config files, so anything that wo

nettcpbinding with windows security in iis hosted service


Hi ,

I have hosted service in iis. How can i verify my service (transport mode)is using windows authentication for client.

when i use basichttpbinding and set clientCredentialType to windows, but iis with anonymous. When i browse svc, as expected i get error that secrurity setting of servcie needs windows but iis is configured as anonymous. Similar i see expected bheavior when service is configred for anonymous, but iis is configured for windows.

But when i use nettcpbiding, irrespective of what my iis setting is (windows/anonymous), if i configure service for windows and i browse svc file. I am always able to do to without any error. when service is configured for windows and iis for anonymous; shouldn't i get an error (as seen in case of basichttpbinding)



How to debug Windows Workflow when it is hosted by WCF Service ?



I have build a test solution in two parts :

1) WCF service which hosts a Windows Workflow (statemachine).

2) Console application which consumes the WCF Service.

It works well, but if I do a bad process, it crashes which is normal. Exemple : the client calls an event which is impossible to execute given the current state according to the workflow design. In this case, the client receives a WCF exception. This exception is masked, which is normal (an option has to be set in WCF side to enable exception transmission).

The problem is that, althought I launched the console application with the debugger, with the WCF service project, the debugger doesn't break on Workflow errors in WCF error side. (However, I saw that non-Workflow errors in WCF side are still stopped by the debugger)

How could I force the VS debugger to break on Workflow WCF errors ?


(Workflow 3.5)

How to create a WCF web service using TCP protocol hosted on windows services and compatible with no



I need to create a WCF web service . My service will operate on LAN hence I wish to use TCP protocol for that.

So I need to host that web service on windows service.

But I don't know how to make that web service compatible with other platforms.

I wish my service should be platform independent.

If anybody knows the solution then pls let me knw.

How to enable windows authentication for a RESTFul web service which is not hosted in IIS


I have created a WCF RESTFul webservice by following http://msdn.microsoft.com/en-us/library/dd203052.aspx. I am hosting my RESTful webservice in a window service (and not IIS) using the WebServiceHost class. 

Now I am struggling to get user's windows credentials in my web service methods. I looked at various code samples in forums for this. Almost all of them are hosting the service in IIS plus configuring  the service's settings using <system.serviceModel> tag.

I don't want to host my service in IIS plus as of now I haven't overridden any EndPoints, Behaviours etc in .config file.

I tried with below code in my window service's onstart method

WebServiceHost host = new WebServiceHost(typeof(MyService), new Uri(_serviceUrl));

ServiceAuthorizationBehavior myServiceBehavior = host.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
myServiceBehavior.PrincipalPermissionMode = PrincipalPermissionMode.UseWindowsGroups;


After putting above code I queried ServiceSecurityContext.Current and System.Threading.Thread.CurrentPrincipal  my RESTFul's method but they are showing no sign of return

WCF service hosted in a Windows Service Automatically Starting


I stop the Windows service that hosts the WCF application, it stops, then it starts back up. Service recovery options are disabled.


It is somehow starting itself back up…   Any ideas as to why?

Kevin Burton

wcf service host by windows service - client cannot connect



i have created a cf service hosted by windows service. the wcf service app.config is

<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation.  All Rights Reserved.-->

      <service name="DiscoveyService.WCFDiscoveryService">

MSMQ Recieve Activty fails in workflow hosted in Windows Service



I am trying to implement a windows service hosted workflow service that polls from a message queue. The message queue is is populated by a separate windows service.

I followed the post below for my hosted workflow as it looked to be close to what I was trying to do.


Following the steps in the post I was able to get my service to work when the message body was a simple string and using the WCFTestClient.

I then changed the code to use a a custom .NET object as the Recieve parameter instead of the string. The class library in which the object is defined was added as a reference. The service that populates my queue uses the custom .NET object as the message body.

In this scenario, the service would run but only process a message from the queue if it was in the queue before the service started. Any new messages added are ignored and if I add the message after I start the queue it also does not get picked up.

My xamlx is below, followed by my app.config:



WCF REST webservice hosted in a windows service


Hi, I created a WCF REST service which had a method "Result":



public interface IService


   [OperationContract(Name =  "Result")]

   [WebGet(UriTemplate = "/")]

   string Result();


When I went to the default page http://localhost:portnumber/Service.svc it would display the string returned by Result().


I then wanted to host the WCF service in a Windows Service. The service is running fine and I can browse to the baseAddress. However in this setup it displays the default "You have created a service" page and doesn't execute the method returning the string.


I'm not even sure if this is possible. In summary is it possible to how a WCF REST service in a Windows Service and get it to respond to HTTP GET requests?


Can anybody suggest a solution?





WCF hosted in a Windows Service is not available over network


I have WCF service which is hosted using Windows Service.

Also I have a client (Windows Forms) which communicates with my WCF.

When I test it on my PC (using localhost) it works fine, but when I try to test it over network it doesn't work: I receive the following error: "TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time..."


When I use Windows Forms for hosting my WCF, it works fine.


Here is source code of the service:


var throottling = new ServiceThrottlingBehavior
       MaxConcurrentCalls = Int16.MaxValue,
       MaxConcurrentSessions = Int16.MaxValue,
       MaxConcurrentInstances = Int16.MaxValue

var address = string.Format("net.tcp://{0}", Settings.ServerAddress);
var binding = new NetTcpBinding(SecurityMode.None) { HostNameComparisonMode = HostNameComparisonMode.Exact };


Windows Service Applications Tutorials

You can easily create services by creating an application that is installed as a service. For example, suppose you want to monitor performance counter data and react to threshold values. You could write a Windows Service application that listens to the performance counter data, deploy the application, and begin collecting and analyzing data.

Extreme ASP.NET: Client-Side Web Service Calls with AJAX Extensions


Microsoft AJAX Library and the ASP.NET 2.0 AJAX Extensions provide a number of compelling features ranging from client-side data binding, to DHTML animations and behaviors. Learn all about them here.

Fritz Onion

MSDN Magazine January 2007

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend