0

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.

enter image description here

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 cannot 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?

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
  • check if there is any error logged in the event viewer. – Sachin Shanbhag Mar 29 '11 at 12:02
  • If the service stops before you are able to attach a debugger, have a look at the answer to [this](http://stackoverflow.com/questions/5266971/null-reference-exception/5267016#5267016) question on how to break. – Nils Magne Lunde Mar 29 '11 at 12:07
  • @Sachin and @Ole_Brun : Thanks for the input. I have added the eventViewer Error to my question. Please check that out and Please tell me what could be wrong? – Parth Bhatt Mar 29 '11 at 12:50

4 Answers4

1

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.

Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • Thanks for the input. How can I view eventLog? Even How can I use `try` `catch` for the above line? Can you please explain it with a bit of code? – Parth Bhatt Mar 29 '11 at 12:31
  • I have added the eventViewer Error to my question. Please check that out and Please tell me what could be wrong? – Parth Bhatt Mar 29 '11 at 12:47
  • 1
    Check your config file, it's not correct for the service. Check that you have a config file at all, try recreating the web service reference, or failing that create a console app with the service call, debug that (its easier), then make it into a service again. – Kieren Johnstone Mar 29 '11 at 13:01
0

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

DevExpress Team
  • 11,338
  • 2
  • 24
  • 23
  • How can I view EventViewer? Where is it located? I am a newbie and don't know much about it – Parth Bhatt Mar 29 '11 at 12:33
  • Computer-->Manage-->Event Viewer – DevExpress Team Mar 29 '11 at 12:37
  • Thanks for the input. I have added the eventViewer Error to my question. Please check that out and Please tell me what is wrong? – Parth Bhatt Mar 29 '11 at 12:47
  • @DevExpress Team: May be you gave a wrong link. You have provided me link which redirects to www.google.co.in thats it. – Parth Bhatt Mar 29 '11 at 13:06
  • Just type the error's text in google.com. My link should redirect you to google.com page – DevExpress Team Mar 29 '11 at 13:07
  • @DevExpress Team: I know that there is something called Google. If I would have got that on google then I am not mad to put a question on it here on stackoverflow. So it is better that you put some useful links if you know. This is something not expected out of you. You being an old and reputed member of Stackoverflow.Nothing Personal..!! – Parth Bhatt Mar 29 '11 at 13:17
  • Also see what I got on google when I pasted some portion of my error into it. This is my own question which is shown on loopingrecursion.com. Anyways. http://www.google.co.in/webhp?sourceid=navclient&ie=UTF-8#hl=en&source=hp&biw=1308&bih=533&q=Service+cannot+be+started.+System.InvalidOperationException:+An+endpoint+configuration+section+for+contract+%27MyServ.MyServSoap%27+could+not+be+loaded+because+more+than+one+endpoint+configuration+for+that+contract+was+found.+Please+indicate+the+preferred+endpoint+configuration+section+by+name.&rlz=1R2GGHP_enIN411&aq=f&aqi=&aql=&oq=&fp=7dcf5071bbfdf296 – Parth Bhatt Mar 29 '11 at 13:22
  • The error text you've posted means that the WCF service (am i right, is it a WCF service?) is configured wrongly. I do not know how it is configured, as you did not post information about it. However, there are a lot of information on this error in google where this exactly error is discussed. So, I've posted a link to it just because you can find something usefull there. I am sorry for the confusion. But having this information only it is impossible to determine what is wrong with your WCF service. – DevExpress Team Mar 29 '11 at 13:22
  • Please input the following text into google.com search bar: An endpoint configuration section for contract could not be loaded because more than one endpoint configuration for that contract was found. I've found a lot of entries using this search request... – DevExpress Team Mar 29 '11 at 13:25
  • ok no problem. Sorry if I have been harsh..!! I have configured my service by "add Service Reference" from the VS2008 solution explorer and then simply typing in the URL of my webservice and then Pressing OK button. Then I can use it as I have done in my code. What is the correct way to do that? I am a newbie into windows services – Parth Bhatt Mar 29 '11 at 13:26
  • I think you did not understand me. If I understand error correctly. the problem is in the TempWindowService.MyServ.MyServSoapClient service... – DevExpress Team Mar 29 '11 at 13:27
  • Problem was in `app.config` file – Parth Bhatt Mar 29 '11 at 13:39
  • I am glad that you have found the cause of this issue :-) – DevExpress Team Mar 29 '11 at 13:40
  • **Deleted** the Service Reference and app.config file and **Re-created** and **added** the service reference again.app.config file was created automatically. This worked for me. Hoope this helps those looking out for a solution to this. :) – Parth Bhatt Mar 29 '11 at 13:42
0

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.
VitalyB
  • 12,397
  • 9
  • 72
  • 94
  • 2
    That's a bit random. Instead I suggest: `while (!Debugger.IsAttached) { Thread.Sleep(1000); } Debugger.Break();` that way it waits until the debugger is attached – Kieren Johnstone Mar 29 '11 at 13:00
  • Good call @ Debugger.IsAttached :) – VitalyB Mar 29 '11 at 13:04
  • Just remember to take that code out when deploying, else your service will be waiting for a debugger to attach. Best make it a .config option, WaitForDebugger etc – Kieren Johnstone Mar 29 '11 at 15:20
0

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");
Nils Magne Lunde
  • 1,794
  • 1
  • 13
  • 21