Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Windows Service with WCf

More
09 Dec 2014 09:52 #2555 by support
Replied by support on topic Windows Service with WCf
We do not have an out-of-box example for the combination you described.
As a proof of feasibility, in the examples solution for C# and VB.NET, we have a very simple WCF service project (called Web\WcfService1), and a client to it (called Console\WcfClient1).

The service contract:
using System.ServiceModel;
 
namespace WcfService1
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IService1
    {
 
        [OperationContract]
        string GetData();
    }
}

The service implementation:
// WcfService1: A simple Web service using WCF technology. Provides a GetData method to read a value of an OPC item.
// Use WcfClient1 project (under Console folder) to test this Web service.
 
using OpcLabs.EasyOpc.DataAccess;
 
namespace WcfService1
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Service1 : IService1
    {
        public string GetData()
        {
            var easyDAClient = new EasyDAClient();
            object value = easyDAClient.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Ramp");
            return (value == null) ? "" : value.ToString();
        }
    }
}

The client:
// WcfClient1: Using a Web service provided by the WcfService1 project (under Web folder), gets and displays a value of 
// an OPC item.
 
using System;
 
namespace WcfClient1
{
    class Program
    {
        static void Main()
        {
            var client = new Service1Client();
 
            // Use the 'client' variable to call operations on the service.
            Console.WriteLine(client.GetData());
            Console.ReadLine();
 
            // Always close the client.
            client.Close();
        }
    }
}

What you described should be doable. If you run into any specific issues, let me know and we will try to help.


Best regards

Please Log in or Create an account to join the conversation.

More
08 Dec 2014 20:15 #2552 by neilcooley
Hi

Do you have any examples of Windows Service communicating to a Windows Form using WCF?

I am thinking of something along these lines;

Windows Service, ItemChanged event, updates a list with real time values

Windows form via WCF, polls that list and displays the values in a listview.


Neil

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.042 seconds