|
-
October 13th, 2011, 03:55 PM
#1
Windows Service Won't Stay Up
Hello guys. At my first attempt at learning this stuff I'm stuck in that this service named MathService stops shortly after it starts. I go to control panel/administrative tools/services I click start on the service. A message pops up saying that the service was started then stopped and that some services are stopped if they aren't being used. I'm trying to to write the client program. But I'm stuck at the point of adding a service reference. I enter http://localhost:8080/MathService press enter when at the "add service reference" and it can't find it. I'm thinking it's because the service isn't running. But I can't get the service to stay running. This is the service code if that's the problem. Can someone please help me wiht this?
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using MathServiceLibrary;
using System.ServiceModel;
namespace MathWindowsServiceHost
{
public partial class MathWinService : ServiceBase
{
private ServiceHost myHost;
public MathWinService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (myHost != null)
{
myHost.Close();
myHost = null;
}
//create the host.
myHost = new ServiceHost(typeof(MathService));
// The ABCs in code
Uri address = new Uri("http://localhost:8080/MathServiceLibrary");
WSHttpBinding binding = new WSHttpBinding();
Type contract = typeof(IBasicMath);
//add this endpoint
myHost.AddServiceEndpoint(contract, binding, address);
//open the host.
myHost.Open();
}
protected override void OnStop()
{
//shut down the host.
if (myHost != null)
myHost.Close();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|