Rafael Zuniga, Stephen Cave
Summary:
This lab will focus on creating and installing a Windows Service Host. A client will also be made which will be able to use the host.
Procedure:
We being by opening the existing solution which can be found in Chapter4/WindowsServiceHost in the labs directory. Next we add a new Windows Service project and rename the default service to MessagingServiceHost. The default constructor is modified as follows:
public MessagingServiceHost()
{
InitializeComponent();
this.ServiceName = "MessagingServiceHost";
}
Next we add a new application configuration and add a service model section which will expose an endpoint for our client to use. A reference to the Messaging project and the ServiceModel assembly is added. The OnStart and OnStop events are modified so the service begins and closes when the service is started and stopped:
protected override void OnStart(string[] args)
{
m_serviceHost = new ServiceHost(typeof(Messaging.MessagingService)); m_serviceHost.Open();
}
protected override void OnStop()
{
if (m_serviceHost != null) m_serviceHost.Close(); m_serviceHost = null;
}
A reference to Configuration.Install is added in order to create an installer for the service. The project is then compiled and the service is installed successfully:

And we can see the that the service can be found in the service management console:
A proxy for the client is then generated using svcutil.exe and the generated App.config and serviceproxy.cs are added to the project. A new click event is added to the client's call service button:private void button1_Click(object sender, EventArgs e)
{
MessagingServiceClient proxy = new MessagingServiceClient();
MessageBox.Show(proxy.SendMessage(string.Format("Hello from {0}",
this.Text)));
}
The project is then compiled. And that's about it. There's problems running the service and when it does run it hates the client with a fiery passion. See below.
Observations:
- Windows Vista/7 are really harsh on what can and can't run
- The service installs fine but is unable to run due to the Network Service account not having enough privileges
- Changing the account to run the service under to system account allows it to run fine
- The problem is then on the client's end because it will not connect to the host giving the error "Credentials Rejected"
- To get around this the client must impersonate the credentials of a user with administrative access
- Even then it doesn't work due to the alignment of the moon and stars
No comments:
Post a Comment