locked
WCF and Windows service RRS feed

  • Question

  • Hello. Please, can somebody advise me? I create WCF library that realizes endpoint net-pipe for job with external WCF.I placed lib in Windows Service. But I dont know how to make data exchange from library without usage of WCF client-server mechanism. How can I put or get data from running WCF service? for example I want to register WCF errors in Eventlog or give parameters to service for transfer them for clients connected to WCF. Thanks a lot
    Wednesday, August 8, 2012 12:42 PM

Answers

  • Hi,

    NetNamedPipeBinding is the best choice to do data exchange between two process. You need to create a client-service communication.

    More, why do you need to communicate between the hoster(windows service) and wcf service? I think the data should be maintained in the wcf Service directly.

    More, as you mentioned that you don't want to use client-service communication between the two process.

    So how about try to store the data in the database and let the windows service to check the database every second.

    • Marked as answer by Otomii Lu Thursday, August 16, 2012 8:45 AM
    Monday, August 13, 2012 6:04 AM

All replies

  • Hi,

    I was a little confused with your requirement. I will try to solve the two situations you mentioned.

    " I want to register WCF errors in Eventlog "

    You can enable WCF tracing to get more information about the issue:

    http://msdn.microsoft.com/en-us/library/ms733025.aspx

    http://msdn.microsoft.com/en-us/library/ms732023.aspx

    "give parameters to service for transfer them for clients connected to WCF"

    I guess you have lots of clients which have registered themselves to the WCF Service. Then when you give paramters to the Service, you want the Service to push to data to them.

    For this situation , what you need is Duplex Service:

    http://msdn.microsoft.com/en-us/library/ms731064.aspx

    Hope helpful.

    Thursday, August 9, 2012 8:12 AM
  • Thanks.

    In my project i need to create Silverlight or WPF client for industrial monitoring in my plant  in the real time. For this I would like to use duplex channel in  wcf service on the my OPC client

    I have two objects in my Windows Service project. One object is OPC client and database client. If i create this object in code - everything works good. Another object is WCF service library with net.pipe binding for external connection to this service. Ok. I define in my code:

    // window service class   
     public partial class SyncSiemensService : ServiceBase
        {
            private OpcServiceClass opcServer = new OpcServiceClass();

            public SyncSiemensService()
            {
                InitializeComponent();
            }

            protected override void OnStart(string[] args)
            {
                      // OPC client- database client object
                      opcServer.Start();

                     // WCF interface for external communication
                     // with this windows service
                      using (ServiceHost host = new ServiceHost(typeof(DuplexPipeWcfService)))
                                 {
                                     host.Open();
                                     eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);
                                 }
            }
    }

    WCF service

            [OperationContract(IsOneWay = true)]
            void GetActValuesFromLine(string line);

    string line - external data FOR opc object

    and his callback

        public interface IDuplexPipeWcfServiceCallback
        {
            [OperationContract(IsOneWay = true)]
            void ActualValuesUpdate(WcfDuplexActualValues value);
        }

    but "WcfDuplexActualValues value" in mine occurrence - data from OPC object for external connection in WCF. And now i dont know, how retrieve data from opc object without usage client-service communication between OPC object and WCF service library.

                  

    Thursday, August 9, 2012 10:09 AM
  • Hi Little_Cat_2003,

    According to your description, I still cannot understanding the problem you are facing.

    >What client you are using? Silverlight or WPF client? If you are using Silverlight , you need to provide a cross-domain file for your WCF Service.

    >Please try to use Fiddler to monitor the data transfer, if the data not transfer ,there will be errors at server-side. It would be appreciated if you can provide me the web.config file.

    >More examples that might help you:

    http://msdn.microsoft.com/en-us/library/ms751522.aspx

    Friday, August 10, 2012 7:57 AM
  • excuse me for inaccuracy in describing my problem. I created windows service project. It starts and works. This service archives in database some data, refreshing them from the outside and storing about 300 elements of own array. Now it`s need to display at client system some data of this service at realtime. For example display 2-3 service array elements depending to user choice. For this I want to use WCF service. No problem to make working service with duplex channel. Question is how to cross working windows service and WCF process. I need to perform data exchange between these 2 processes.
    In my project I have class serviceMyWinService which does data archiving logic.  In Windows service project it is placed in OnStart event like

    protected override void OnStart(string[] args)

    {

    serviceMyWinService service = new serviceMyWinService();

    service.Start();

    }

    This object works in service. Then WCF service library:

    using(ServiceHost host = new ServiceHost(typeof(myWCF))
    {
       host.Start();
    }

    also in OnStart event. And the question is: how to do data exchange between them without creating client connection of service to host.


    I never see any example in internet in which WCF service constructor was used for creating threads and objects in WCF service for continous working code. It would be perfect way to do.
    My serviceMyWinService is realized in WCF service. But if it is possible show me please link to such way and example. Thanks a lot.
    Sunday, August 12, 2012 11:52 AM
  • Hi,

    NetNamedPipeBinding is the best choice to do data exchange between two process. You need to create a client-service communication.

    More, why do you need to communicate between the hoster(windows service) and wcf service? I think the data should be maintained in the wcf Service directly.

    More, as you mentioned that you don't want to use client-service communication between the two process.

    So how about try to store the data in the database and let the windows service to check the database every second.

    • Marked as answer by Otomii Lu Thursday, August 16, 2012 8:45 AM
    Monday, August 13, 2012 6:04 AM
  • Thanks.
    Monday, August 13, 2012 8:28 AM
  • Did you ever find an answer to your problem. I am doing something similar - I am able to use DataChangeEvents to keep the application in a continuous run mode, other than that I do not know any other way to keep the datapath open. For example read and write events would need to be called if your application is just getting data  every so often - and for that you would need to keep your connection alive and open.

    If your app has any differences - than what I outlined - perhaps you could assist me to know some other ways of doing this, before I go and say here tis.
    Tuesday, April 28, 2015 3:22 PM