locked
Interface WCF with Windows Service? RRS feed

  • Question

  • I am completely new to WCF and was hoping that someone could review my concept and tell me if it is viable.

     

    I intend to create a Windows Service that gathers and holds various bits of data in some classes. I would like to have a some web clients make a request for the data, assuming it would be through WCF. WCF “asks” the Windows Service for the data and the Windows Service returns it back in the form of a structure. WCF will then run it through a JSON Serializer and onto the clients. I hope I’m making some sense. Does this sound like a viable approach? If so I’m a bit fuzzy on how to interface the Windows Service with the WCF service.

     

    Thanks!

    Tuesday, May 10, 2011 7:46 PM

Answers

  • You can use any host, such as IIS. The problem with IIS is by default, the application pool will be recycled once a while. But in most cases, the impaction is a minimum. The next time a client request the service, the service needs to start again, which may be a bit slower, and all in memory data (such as in memory cache and session) are lost. But in most cases they're acceptable. Windows Service doesn't support recycling and thus doesn't have the problem, but when the service is hosted in Windows Service, you can't use ASP.NET features. You can also configure IIS to disable application pool recycling if you like.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Peak Creek Tuesday, May 17, 2011 1:14 AM
    Friday, May 13, 2011 1:23 AM

All replies

  • If you are writing the whole thing from the scratch why you need WCF service to communicate with Windows service. 

    You can write a WCF service and host it as a windows service. 

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

    Having said that, you are not restricted to allow your WCF service to talk to any windows service. You can use NetTcp binding for this. 

     

    WCF by default uses DataContractSerialization. But you can use JSON Serialzation as well, which is part of System.Runtime.Serialization Namespace ... in particular System.Runtime.Serialization.JSON ... and the class is DataContractJsonSerializer



    Tanvir Huda Application Architect/Consultant
    Wednesday, May 11, 2011 1:58 AM
  • Thank you for your response Tanvir. It is probably lack of my understanding WCF is the reason why I was thinking of using a Windows Service. First, this service needs to run 100% of the time while it collects data. The clients (web clients), apprximately 6 of them, will be requesting updates a couple of times a minute. This system will run 24/7 except for a couple of vacation breaks a year. Secondly I needed to expose a couple of methods for manipulation of some configuration settings. I'm assuming that could be done easily in WCF.

    I will read the article in the link you posted and I have also found a couple of tutorials that may be helpful, but I'm sure I will have a lot of other questions. I like your idea of putting everything into WCF and if you don't see any problems with the things I mentioned above, then I will proceed in that direction.

    Wednesday, May 11, 2011 11:08 AM
  • This isn't working too well. I need to add some data sources to my WCF project and the Data menu doesn't offer the option to add a data source.
    Wednesday, May 11, 2011 1:02 PM
  • This isn't working too well. I need to add some data sources to my WCF project and the Data menu doesn't offer the option to add a data source.


    So I'm assuming that access to databases is done through code??? No problem I just need to know that is what has to be done. I told you I am a rookie.

    I suppose the DataSource Wizard is used if binding data to controls... which we don't have in a WCF service.

    Wednesday, May 11, 2011 1:54 PM
  • Hello, how to implement a WCF service is up to you. For example, you can create an Entity Framework model to access database, just as you do in other projects (like in WPF and ASP.NET). But data source is for client using only. You can use it to bind data to controls for display/editing. A service does not need to display data, it also doesn't need to collect user input via controls to update data. So data source doesn't apply to services.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Thursday, May 12, 2011 2:52 AM
  • Thank you Yi-Lun Luo. So is it possible for WCF to start and run continously so that the data is kept up to date and ready for whenever a client asks for it?


    I found this post which indicates that to keep running continuously WCF shouuld be run within Windows Service http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/7b424d52-6790-4dc9-9750-b6a70e57699b/
    • Edited by Peak Creek Thursday, May 12, 2011 12:14 PM addl. info.
    Thursday, May 12, 2011 12:07 PM
  • You can use any host, such as IIS. The problem with IIS is by default, the application pool will be recycled once a while. But in most cases, the impaction is a minimum. The next time a client request the service, the service needs to start again, which may be a bit slower, and all in memory data (such as in memory cache and session) are lost. But in most cases they're acceptable. Windows Service doesn't support recycling and thus doesn't have the problem, but when the service is hosted in Windows Service, you can't use ASP.NET features. You can also configure IIS to disable application pool recycling if you like.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Peak Creek Tuesday, May 17, 2011 1:14 AM
    Friday, May 13, 2011 1:23 AM