Error in Windows service While starting the service
I have created a windows service.
When I try to start my service after installing it on my local computer then it gives me error.
My other windows service work well only this specific service gives this error so the problem is not related to Windows but something to do with my service.
What could be wrong?
This is my Windows Service:
namespace TempWindowService
{
public partial class Service1 : ServiceBase
{
System.Threading.Thread _thread;
public Service1()
{
InitializeComponent();
}
// System.Timers.Timer tm = new System.Timers.Timer(10000);
protected override void OnStart(string[] args)
{
TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient();
//newService.BatchProcess();
_thread = new Thread(new ThreadStart(newService.BatchProcess));
_thread.Start();
// tm.Interval = 1000;
//tm.Elapsed += new ElapsedEventHandler(TimerElapsedEvent);
// tm.AutoReset = true;
// tm.Enabled = true;
}
public void StartNew()
{
TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient();
newService.BatchProcess();
}
private static void TimerElapsedEvent(object source, ElapsedEventArgs e)
{
}
protected override void OnStop()
{
}
}
}
I am calling the webservice from the windows service by adding service reference
This is what the error shows in EventViewer
Service cann开发者_StackOverflowot be started. System.InvalidOperationException: An endpoint configuration section for contract 'MyServ.MyServSoap' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
at System.ServiceModel.Description.ConfigLoader.LookupChannel(String configurationName, String contractName, Boolean wildcard)
What could be wrong?
This line is likely throwing an exception:
TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient();
Check your configuration file is present and correct; the event log viewer will let you know what the problem is.
Consider using try
and catch
to look for startup errors and report them in a useful way.
Take a look at the EventViewer, I am sure, it will contain some useful information related to this error. Also, you can debug it by using the approach shown at:
How to: Debug Windows Service Applications
You will find a lot of information about this error at:
http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=An+endpoint+configuration+section+for+contract+could+not+be+loaded+because+more+than+one+endpoint+configuration+for+that+contract+was+found
If EventViewer doesn't help you, you should try debugging it using one of the following ways:
- Put a "Debugger.Break" under OnStart and connect with a debugger.
- Put a 10 seconds sleep under OnStart and connect with a debugger during the delay.
If you have multiple endpoints with the same contract type in the config file for your service, you need to specify which one you are interested in:
TempWindowService.MyServ.MyServSoapClient newService = new TempWindowService.MyServ.MyServSoapClient("EndPointName");
精彩评论