I've been handed a project that needs some work doing and the original team that created it have all since left the company. This has been sat "on-the-shelf" for 4 years and everyone but our client had forgotten about it. They want it delivering now and it doesn't work.
The system is a relatively simple ASP Web Forms application for submitting data to another service via 2 WSDL interfaces, logging that request in a SQL database and submitting the response to another service via OPC.
I can set up all of those interfaces for testing except the WSDL. I just have the software here to run. Is there any way I can easily create a service to simulate the final one so I can test my software. I only have the 2 WSDL files to go on. These aren't complicated services. I'm only using 4 methods total.
I've been led to believe that the original creator of this system did something similar but I can't find what he used or any documentation about it. I expect it was run on his laptop and was lost when he left the company.
The WCF service client should be wrapped and exposed via an interface to your software. That way, you can mock the interface and test how your software responds to various inputs/outputs from the mocked service client. You control all aspects of what is returned, including potentially throwing exceptions as the real WCF service client would.
This is basically the reason why the "I" in SOLID exists - because substitution of implementation based on interface is simple to do.
I'd like to have a List<int> that multiple instances of my application can access. At the moment I can cheat and use a global mutex but that hardly would work well after 10K ints. How do I get multiple instances of a program to share a list?
An easy way to do that is to put this data in a custom windows service.
Host in this service the data you want to share and provide access to this data using any kind of IPC. The simplest is WCF.
Another method may consists in having only one instance of the application. Instead of having on form in your app, manage multiple forms as separate "pseudo" instances. When firing the app again, check if the app is already launched and trigger a message to this app.
Lastly, as Raja suggest, use a queue to share data between apps. But this requires more information about how and when the list is populated.
Our application requires now that one of its components will be started in its own dedicated process.
I have just come across the AddInProcess class (from System.AddIn.dll)
Unfortunately i couldn't find any useful code examples or projects that use this infrastructure.
I am wondering what are its pros/cons against rolling our own out of process infastructure?
Our application uses .NET 3.5 (WinForms)
The component that should be loaded out of process is an execution engine that loads arbitrary user code and executes it.
One note to consider is the fact that this component that executes code, needs to pass back a Results object to the calling application.
I would say it depends on what sort of interface into the component you need.
If it is simple, i.e. the functionality needed is in a single function or two, you could just start a process to do it, passin an argument if needed.
If it is more complex, you could create a WCF host process and expose a service interface.
I have three windows services in one C# project. Using the installer class (it contains three service installers and one process installer) I was able to install all of my services and start them as three different windows services.
Now I'm trying to run those services under one service name (I would like to see one service name in service control manager, not three). What would be the best approach to do this?
Thanks in advance!
You could just have one main service that spawns off the other executables as regular processes (see Process.Start(..)) which would not show up as windows services. That service would have to control the life time of the dependent processes (start them after the service was started /stop them before shutdown).
Create a new windows service and start 3 thread.
All you have to do is implement some principles of code reuse.
Move each of the respective work units into classes/libraries rather than services. Create a single service referencing the end result libraries. Your service intention is likely a timer of some sort, and possibly exposing API endpoints. Create the single service and activate the necessary classes from 3 unique timers (if needed - you might get away with a single timer activating 3 different class methods). Wrap events or API endpoints in a similar fashion. A services should contain little or no "business" logic, it should derive that work from referenced business libraries. Follow that practice and your question will mostly answer it's self.
I am trying to build several Windows services to do different things. For instance, I need Windows services that will:
Send a daily report via email
Periodically cleanup some archived info every 30 minutes
etc.
The tasks I need the windows services to do are distinct so I don't really like the idea of having them all in one service.
What I've got so far is a project in Visual Studio 2008. I've created a windows service, I've set up a timer on the OnStart event (it just writes to a text file every 5 seconds for testing purposes). I then added an Installer to the project and when I run InstallUtil.exe, everything works fine.
The problem comes in when I add a second windows service to the same project. I set up the OnStart code again, with the same logging info (slightly different so I can tell which service is writing to the log). With the second windows service, I changed the Main event in Program.cs from:
static void Main(string[] args)
{
ServiceBase[] ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
to:
static void Main(string[] args)
{
ServiceBase[] ServicesToRun = new ServiceBase[]
{
new Service1(),
new Service2()
};
ServiceBase.Run(ServicesToRun);
}
At this point, there are no compile time errors, but the Service2 service never does anything...the logging task never fires.
I narrowed it down to the fact that the second service has no "Installer" associated with it. I then tried to add an Installer the way I did with the first service (i.e., right click on the service designer, and click "Add Installer"). Now, when I go to the ProjectInstaller.cs file, there is another serviceInstaller there (serviceInstaller2).
Now when I build the project and try to install the services, and I go to the "Services" control panel window, and I try to start Service1, I get the following error message:
Windows could not start the Service1 service on the Local Computer.
Error 1083: The executable program that this service is configured to run in does not implement the service.
I get the same error message if I try to start Service2 as well (with the exception that the error message identifies Service2, of course).
Is there something I am missing in order to get two services running from one exe?
I have figured out how to have one executable but two services. Each service installs to the service manager with its own name and ability to start/stop. I think this is what you're wanting, correct? Here is what I did:
Created a service project.
Added a second service to the same project (with a unique service name).
Added an installer to both services (ServiceA and ServiceB).
In the ProjectInstaller.Designer.vb file I changed the Me.Installers.AddRange line to show both of the service installers. (Me.ServiceInstaller1, Me.ServiceInstaller2)
In the Main entry point of the main service (ServiceA in my case), I set the ServicesToRun variable to an array of ServiceBase containing all the services that I want it to run (ServiceA and ServiceB). This is an important step as the service manager sets a property based on the number of arguments here - either to allow multiple instances of the same exe or only a single instance.
Add an installer project and use the output of Services.
Add a custom action using the output from Services.
You can find the demo code here: http://code.google.com/p/multi-service-install/
Enjoy!
I guess that you guys have already solved this, but in case that some else needs it, I'll post an answer to this issue which took me several hours today.
The solutions is not to add another project installer, but a service installer, which is a component on the project installer. That newly added service installer has to have second service name configured.
I had a similar problem today, and managed to resolve it.
Firstly, I made sure that each of the services had a meaningful and unique ServiceName property. The generator gave both of the services the same name which would not have helped.
I then removed and regenerated the ProjectInstaller class, and added installers for each of the classes. I made sure they were both instantiated in the static Main method.
I can now install the two services with the one dll, but unfortunately when I start one of the services it seems to perform the functions of both itself and the other service. That is, both of the services are running (even though only one of the services appears as 'Started' in Computer Manager). I'm still trying to figure that one out...
I'm actually building something very similar to what you're thinking of. What I've decided to do (thus far) is have all of my 'services' (though they aren't services, the one 'controller' is) implement a particular interface (with init() and execute() operations as well as a FREQUENCY enumeration).
The controller is the windows service and it reads the list of programs/dlls from an xml settings file at runtime and loads them into a List and calls their execute() method (if applicable) on whatever frequency they have defined.
In my case, each program also contains a usercontrol that is loaded into a tab page of the controller that allows the user to control/modify it. I'll post code if you're interested.
Not sure if that was clear. I actually got the idea from another SO user who implemented something similar but I can't find that post now.
I used sc.exe to accomplish this easily. http://support.microsoft.com/kb/251192
For ex: sc create "My Display Service Name" binpath= "c:\app\mysvc.exe --service"
Note: every equal should have space before its value as you can see for 'binpath'
Installing 2 distinct and unrelated services in one executable has a funny smell to me. While it's possible to get it to work, it doesn't make it right.
From what it sounds like, you need to perform some different tasks at various intervals and your tasks may or may not be related. Have you looked into Quartz.NET? It sounds like a good fit for your needs.
http://quartznet.sourceforge.net/features.html
I had the same problem today and managed to fix it.
In my case I just had to open the *.designer.cs files of my services and make sure that the service name is set correctly. More importantly the same name should be used in the *Installer.Designer.cs and if you have code in *Installer.cs.
I think this error occurs only because of name mismatch.
Hope this helpds