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

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

Need help understanding why to use 'ServiceBase.Run' in Windows Service hosting a WCF service

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :WCF
A year or 2 ago I successfully implemented a WCF service hosted in a Windows Service.  Now I am going to do another one, so I went back to my 1st project.  Based on the following links example (http://msdn.microsoft.com/en-us/library/ms733069.aspx) and my 1st project I implmented the following code: Public Shared Sub Main() ServiceBase.Run(New MyWindowsService()) End Sub Now, I read up on this in the MSDN and understand that registers the service with the SCM and calls the onStart method, correct?  The way I read it, this code is necessary.However, now I am looking at a few newer examples of hosting a WCF service in a Windows Service, and the 'Main' Sub with that 'ServiceBase.Run' call is not even included, but apparently still works.  For example the following MSDN tutorial doesn't use that call at all:  http://msdn.microsoft.com/en-us/library/cc949080.aspx#    It just has the onStart method overloaded which I also do.So my questions are, is that code in Sub Main needed and why?  Doesn't pressing start from the 'Services Manager' console call the onStart method anyways of the service?Thank you,

View Complete Post

More Related Resource Links

WCF Windows service hosting - not starting

Hi every experts i have WCF Service and a Windows service project for hosting that service when i install the win service with installutil and click start in services it show this message : "Windows could not start the Virtual WCF Service service on Local Computer. Error 5: Access is denied." i have this problem with this sample too : http://rapidshare.com/files/415123228/WCFSample.rar how can i fix this? THX

Hosting IIS vs Windows Service !!!!

Hi, could you please explain me about the Pros and Cons Between the Hosting the service in IIS vs Windows Service General Term. why iam asking is,my dev server is installed with IIS 7(win 2k8)which ofcourse supports IIS and windows service(netTCPBinding).so please explain me on the same above.

Hosting web service inside Windows Application

  I would like to host my web service inside windows application. I prepared a short example basing on: http://msdn.microsoft.com/en-us/library/aa529311.aspx I have 2 projects created with default templates: Web Service project where I did not change anything: namespace WebService1 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service() { } [WebMethod] public string HelloWorld() { return "Hello World"; } } } Windows Project in which I changed only the main form class: public partial class Form1 : Form { public Form1() { InitializeComponent(); Uri address = new Uri("soap.tcp://localhost/TestService"); SoapReceivers.Add(new EndpointReference(address), typeof(WebService1.Service)); } } The problem is that when I compile and run this Windows Application, I can`t discover this Web Service. There must be something wrong in my solution. Could you please help me by telling what may be wrong? Thank you for help in advance.MCP

Error 400 when hosting windows streaming service.

WCF, .NET 3.5:I'm sorry if this is redundant, but I'm having problems receiving error: 400 requests. My particular issue is this: If I select my service library within VS the library is test hosted and I can stream large files. My problem is getting a windows service configured to host this service library. I can transfer small files but larger ones are failing with the following stacktrace: <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"> <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"> <EventID>262155</EventID> <Type>3</Type> <SubType Name="Error">0</SubType> <Level>2</Level> <TimeCreated SystemTime="2009-11-18T19:58:07.7808550Z" /> <Source Name="System.ServiceModel" /> <Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /> <Execution ProcessName="ExtractorTestClient.vshost" ProcessID="10768" ThreadID="9" /> <Channel /> <Computer>MyComputer</Computer> </System> <ApplicationData> <TraceData> <DataItem> <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"> <TraceIdentifier>http://msdn.microsoft.com/en-US/library/Syste

deploy a WCF service, hosting in Windows Service with NamedPipe binding


Hi, I developed a wcf service, hosted in Windows service with Namedpipe binding, and  a client application that were both in .net 4.0

both work well in my development computer, in Win 7
when i deployed both service and client in another computer. the service works, but the client cannot access the service.

with EndpointNot Found exception
when I changed binding to wsHttpBinding, the client failed to call the service with SecurityNegotiationException



calling and hosting WCF services from windows service


I have 2 windows services. Both hosting their own WCF service and it works fine.

Now one windows service (let call it the second) does need some information from the first windows service.
So I make the second dependend on the first.
This all works fine untill the second windows service starts (it started the first automatically because of dependency).
I make a call to a wcf method (even before ServiceBase.Run) from inside the second windows service towards the first. This will timeout.

I have tackled this problem by making the wcf call after ServiceBase.Run (in the OnStart method) so it looks like the program is not possible to make a wcf call before it is hosted itself (am I right?).

However when I reboot the computer the second service fails to start (startup type is automatically and the first service is started first).
The dependend service fails to start, after that, when I start it manually it will succeed

How do I make this communication work

Windows service hosting WCF service errors with Error ID 7034, WindowsService service terminated une



We have a number of windows services that are hosting a WCF 4.0 service each (Windows 2003 R2 Stardard SP2)

Invariably we are getting An error from Service Control Manager with this error id:7034

The description states:

"The RMWindowsService service terminated unexpectedly.  It has done this 1 time(s)."

We have 10 services running on 5 servers (Prod, Pre-Prod, Support, Test,Dev)

All servers are Windows 2003 R2 Stardard SP2.

All Services are experiencing the error. 

Some times all together, some times 2-3 at a time, some times, only one errors

On searching on the error this link said that the Error Id meant

"ERROR 7034: NS_E_SOURCEGROUP_NOTPREPARED.This error is due to The source is not yet prepared.%0 .The source of the error code is the Windows Media Server."

On searching for NS_E_SOURCEGROUP_NOTPREPARED , this link confirmed  in part what was said.

But I can find nothing that gives me a root cause of what is causing this error. Which is fair as I wrote the Winservice

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.

Convert WCF service to self hosting application


 I created project as a  WCF Service application and now according to recuriment that needs to be converted as a self hosting application

How can i do this?

Converting WCF service app to Self hosting app?

Web Service Workflows: Deploy Distributed Business Processes With Windows Workflow And Web Services


Due to the distributed nature of a business process it makes sense for a workflow to be deployed as a distributed application. See how Windows Workflow and Web Services hold the key.

Israel Hilerio

MSDN Magazine October 2006

Service Station: Serialization in Windows Communication Foundation


Windows Communication Foundation supports several serialization mechanisms and provides a simple, interoperable foundation for future service-oriented applications. Here Aaron Skonnard explains it all.

Aaron Skonnard

MSDN Magazine August 2006

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

Getting AppDomain.UnhandledException event to work in a Windows Service

Nearly every forum thread I have found on "catching unhandled exceptions in a service" seems to end up where I am.  The supposed solution is the use of the AppDomain.CurrentDomain.UnhandledException event.  But it doesn't work for someone, who then asks why and gets no answer.  Same for me; I can't get the event to happen.  It's as if I need the ServiceProcess version of Application.SetUnhandledExceptionMode(), which doesn't exist. For diagnosing this, I start a timer in a child object of the service and then throw an exception in the timer event handler.  Simple enough to simulate the real situation.  I have tried subscribing to the UnhandledException event in at least a half dozen locations throughout the service, from the Program that runs ServiceBase.Run() to the constructor of the object that owns the Timer, but it never catches this exception. The VS debugger recognizes that the forced exception is unhandled and takes me to the place where is thrown, letting me know it is an unhandled exception. Why doesn't my handler catch it?  Running without the debugger, the exception throws, the timer thread crashes, the service continues merrily along, and nothing gets logged anywhere.  That is NOT the result I need.  What are the people for whom this works doing that I am not doing? How can I at least get the offe

Windows Identity Foundation Security Token Service can't stay logged in

I'm using the Windows Identity Foundation **(WIF)** Security Token Service **(STS)** to handle authentication for my application which is working all well and good. However I can't seem to get any long running login with the STS. From my understanding I shouldn't care about the client tokens at the application level since they can expire all they want to and it should redirect me to the STS and as long as they're still logged in on the STS it should refresh their application token. Yet it doesn't seem to want to keep them signed in. Here's what occurs in my login.aspx on the STS var cookie = FormsAuthentication.GetAuthCookie(userName, persistTicket); if (persistTicket) cookie.Expires = DateTime.Now.AddDays(14); Response.Cookies.Add(cookie); var returnUrl = Request.QueryString["ReturnUrl"]; Response.Redirect(returnUrl ?? "default.aspx"); Which was taken almost directly from existing application using normal Forms Auth. From my web.config <authentication mode="Forms"> <forms loginUrl="Login.aspx" protection="All" timeout="2880" name=".STS" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" /> </auth

Cash Drawer - Method Open threw an exception - Windows Service

Hi All, I'm getting the following exception while calling Open method of Cash Drawer object. Method Open threw an exception.  Could not read the device name key's default value, or could not convert the Programmatic ID it holds into a valid Class ID. Code:   class Class1 { CashDrawer _uniCashDrawer1 = null; DeviceInfo cashDrawerDevice1 = null; PosExplorer posExplorer = new Microsoft.PointOfService.PosExplorer();   public void ClaimCashDrawer() { cashDrawerDevice1 = posExplorer.GetDevice("CashDrawer", "testDrawer"); if (cashDrawerDevice1 != null) { _uniCashDrawer1 = posExplorer.CreateInstance(cashDrawerDevice1) as CashDrawer; if (_uniCashDrawer1 != null) { _uniCashDrawer1.StatusUpdateEvent += new StatusUpdateEventHandler(UniCashDrawer1_StatusUpdateEvent); _uniCashDrawer1.Open(); _uniCashDrawer1.Claim(0); _uniCashDrawer1.DeviceEnabled = true; } } } }   Tha above code works fine if you put the code in WindowsApplication in all POS systems. The same is working if you put the code in Windows Service in all other POS systems. The same is not working if you put the code in Windows Service in Aures Galeo POS systems.  Thanks in advance. Ramakrishnan S

How can I debug Windows Service using Visual Studio?

How can I debug Windows Service using Visual Studio? I wrote in Visual Studio 2008 Command Promt: installutil -i c:\projects\MyProject\bin\debug\win.exe I did Start to may service ,but every time that I want to debug service I get: Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.   What am I doing wrong?   Thanks, Raya        

logoff doesn't work through windows service

Dear Friends, I am facing this problem on Windows 2003 and 2008 Server. On XP it works fine. I have written and Windows Service that takes receives the command and executes tasks such as Logoff, Shutdown, etc. All the commands except Logoff works fine. I tried following ways to perform the Logoff. However it didnt work. Try 1:                 Process.Start("shutdown", "-l"); Try 2:     [DllImport("user32.dll")]     public static extern int ExitWindowsEx(int uFlags, int dwReason);     ExitWindowsEx(0, 0); Try 3:     Process _currentProcess = new Process();                _currentProcess.StartInfo = new ProcessStartInfo("shutdown", "-l -f");                _currentProcess.StartInfo.UseShellExecute = false;                 _currentProcess.Start(); Try 4:     Process.Start("logoff.exe", null); If I write a simple C# based applicatin (not Service) it works fine for all the tries that I have made. I am facing this problem only when I put this code
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