tags:

views:

75

answers:

1

When i create a Windows Service for getting information from a Web Application(ASP.NET c#) for scheduling some task in the client machine.

To consume WCF from the web application. I added WCF reference to Window Service project as a service reference, everything seems fine. It updated app.config file, added service reference etc. it was not working. Any idea will be very helpful.

My Code is shown below

string result = string.Empty;

BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("http://test.com/Service.svc/DevicesService");

using (ChannelFactory<IDevicesService> myChannelFactory = new ChannelFactory<IDevicesService>(myBinding, myEndpoint))
{

    IDevicesService wcfClient1 = myChannelFactory.CreateChannel();
    result = wcfClient1.CheckNetworkConnection(IPLocalHost);

    if (!string.IsNullOrEmpty(result) && result.Equals(IPLocalHost))
    {
        EventLog.WriteEntry("Test connection succeeded");

    }
    else
    {
        EventLog.WriteEntry("No live connection currently available");

    }

    ((IClientChannel)wcfClient1).Close();

}
+4  A: 

I find it easier, when building a windows service, to build a console application that performs the same work as the service will. I abstract out the actual working code (e.g. your code snippet above) into a separate assembly and then just invoke it from either my service's start method or the console's main method.

If you move your code above into a console application, does it work? If it doesn't, can you step through it and let us know where it fails. And when it fails, what exception information are you seeing?

Let us know and we'll help!

David Hoerster