none
Clients exchanging information on wcf. RRS feed

  • Question

  • There is going to be a central service and multiple clients exchanging data. What i want to do is use clientA to write data to the service and a website to  display these information from the service. Is it possible for a service to store data so other clients can retrieve them later? Should i use a database?? 
    • Edited by g90 Monday, December 15, 2014 2:53 PM
    • Moved by Kristin Xie Tuesday, December 16, 2014 8:19 AM move to appropriate forum
    Monday, December 15, 2014 2:53 PM

Answers

  • >>Is it possible for a service to store data so other clients can retrieve them later?

    Yes, that is a very common requirement for a service.

    >>Should i use a database??

    Yes, preferably or probably based on your requirements but a database is a very common and reliable way of storing data.

    You could for example implement one service method that saves data to the database (to be called from clientA) and another method in the same service that retrieves the data from the database (to be called from the website).

    Please refer to the following page for more information about Windows Communication Foundation (WCF) which is Microsoft's framework for building service-oriented applications: http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx

    There is also a WCF forum should you have any WCF specific questions: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf

    Please remember to mark helpful posts as answer and/or helpful and please start a new thread if you have a new question.

    • Proposed as answer by PhGr_ Monday, December 15, 2014 3:34 PM
    • Marked as answer by g90 Tuesday, December 16, 2014 2:46 PM
    Monday, December 15, 2014 3:31 PM
  • Yes, you would need a database. The job of WCF is to allow communications between the WCF client and WCF service in passing data or messgaes between the WCF client and the WCF service. The WCF service can in turn use a classlib project call it the DAL (Data Access Layer) that would do the CRUD (Create, Read, Update and Delete) with the database.

    WCF is not a UI application it is a SOA solution, a mutil user solution with the service servicing multipe clients concurrently.

    http://en.wikipedia.org/wiki/Service-oriented_architecture

    A simple little project that use WCF Web service, which can be applied to an ASP.NET form solution too.

    http://www.codeproject.com/Articles/576820/Basic-Step-by-Step-WCF-WebService

    You should post to the WCF forum for further help.

    http://social.msdn.microsoft.com/Forums/vstudio/en-us/home?forum=wcf

    • Marked as answer by g90 Tuesday, December 16, 2014 2:47 PM
    Monday, December 15, 2014 3:43 PM
  • If you mean there are going to be web pages which show this data then a database is the obvious way to go.

    It is usual for a wcf service to persist data to a database or be supplying data from one.

    It is unusual for a wcf service to be store data within itself - although quit possible.

    Technically, you could store data in one of the various asp.net caches instead of in a database.

    That could be attractive if this data is ephemeral and you don't really want to persist it.

    You could persist data to a database AND cache it.  Reading data from that cache rather than the database - to reduce load on a database server.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by g90 Tuesday, December 16, 2014 2:51 PM
    Monday, December 15, 2014 5:46 PM
  • Thank you!! I will continue any further questions at the appropriate forum!

    Just a quick question, the client will send data to the service and the service will store them is a database. Is it better, the website to retrieve the data directly from the database or through the service? 

     

    It depends on your design but usually (almost always!) it is better to go via the service. You could then put all your data access logic in the same place and only expose data through the service.

    Please remember to mark helpful posts as answer and/or helpful.

    • Marked as answer by g90 Wednesday, December 17, 2014 7:34 AM
    Tuesday, December 16, 2014 2:55 PM
  • In the past I've worked on web applications which had no web services, wcf or otherwise.

    These are regular asp.net apps.

    There are web pages read and write data to a database.

    Since this is asp.net the actual c# is running on a web server.

    From the web server they read and write data to a database using ado or entity framework.

    There is nothing inherently wrong with no web service at all if that's what you wanted to do.

    This approach is best suited to small -ish applications and probably intranet /extranet rather than end consumer web.

    If you're rewriting Amazon's inventory control system you will want something rather more sophisticated

    There are a lot more small to medium sized businesses with small to medium systems out there than there are huge companies.

    I would say this is still a pretty common architecture.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by g90 Wednesday, December 17, 2014 9:24 AM
    Tuesday, December 16, 2014 3:41 PM
  • This is another question.

    You should really be starting a new thread per question.

    .

    If you want to show updates on a web page there are several issues.

    1)

    You need to know there's been a change.

    One mechanism.

    A trigger on each database table adds an entry to a table stating table y record x changed by user z change type I/U/D and a timestamp.

    Once you know what changed and when you need the clients to read that or a process to push those to the clients.

    Or

    The client needs to re-read their data regularly.  This is obviously inefficient but simple.

    2)

    The client needs to get that data and show it.

    You can do a page refresh with a meta tag which means the page reads the data again every 5 minutes or whatever.  That assumes you only have a few clients though and the page will actually refresh. 

    With WCF you can do something called a long poll.  google it. Gone out of favour now that jquery etc makes "code" on the client more practical.

    SignalR allows you to push data to the client.  This is what I'd usually use nowadays for this sort of requirement.  Google it.


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    • Marked as answer by g90 Thursday, December 18, 2014 7:33 AM
    Wednesday, December 17, 2014 9:51 AM

All replies

  • >>Is it possible for a service to store data so other clients can retrieve them later?

    Yes, that is a very common requirement for a service.

    >>Should i use a database??

    Yes, preferably or probably based on your requirements but a database is a very common and reliable way of storing data.

    You could for example implement one service method that saves data to the database (to be called from clientA) and another method in the same service that retrieves the data from the database (to be called from the website).

    Please refer to the following page for more information about Windows Communication Foundation (WCF) which is Microsoft's framework for building service-oriented applications: http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx

    There is also a WCF forum should you have any WCF specific questions: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf

    Please remember to mark helpful posts as answer and/or helpful and please start a new thread if you have a new question.

    • Proposed as answer by PhGr_ Monday, December 15, 2014 3:34 PM
    • Marked as answer by g90 Tuesday, December 16, 2014 2:46 PM
    Monday, December 15, 2014 3:31 PM
  • Yes, you would need a database. The job of WCF is to allow communications between the WCF client and WCF service in passing data or messgaes between the WCF client and the WCF service. The WCF service can in turn use a classlib project call it the DAL (Data Access Layer) that would do the CRUD (Create, Read, Update and Delete) with the database.

    WCF is not a UI application it is a SOA solution, a mutil user solution with the service servicing multipe clients concurrently.

    http://en.wikipedia.org/wiki/Service-oriented_architecture

    A simple little project that use WCF Web service, which can be applied to an ASP.NET form solution too.

    http://www.codeproject.com/Articles/576820/Basic-Step-by-Step-WCF-WebService

    You should post to the WCF forum for further help.

    http://social.msdn.microsoft.com/Forums/vstudio/en-us/home?forum=wcf

    • Marked as answer by g90 Tuesday, December 16, 2014 2:47 PM
    Monday, December 15, 2014 3:43 PM
  • If you mean there are going to be web pages which show this data then a database is the obvious way to go.

    It is usual for a wcf service to persist data to a database or be supplying data from one.

    It is unusual for a wcf service to be store data within itself - although quit possible.

    Technically, you could store data in one of the various asp.net caches instead of in a database.

    That could be attractive if this data is ephemeral and you don't really want to persist it.

    You could persist data to a database AND cache it.  Reading data from that cache rather than the database - to reduce load on a database server.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by g90 Tuesday, December 16, 2014 2:51 PM
    Monday, December 15, 2014 5:46 PM
  • Thank you!! I will continue any further questions at the appropriate forum!

    Just a quick question, the client will send data to the service and the service will store them is a database. Is it better, the website to retrieve the data directly from the database or through the service? 

    I would like the data to be shown on the website live, without the need to refresh the website so that is will retrieve the data again. 

     
    • Edited by g90 Tuesday, December 16, 2014 2:55 PM
    Tuesday, December 16, 2014 2:51 PM
  • Thank you!! I will continue any further questions at the appropriate forum!

    Just a quick question, the client will send data to the service and the service will store them is a database. Is it better, the website to retrieve the data directly from the database or through the service? 

     

    It depends on your design but usually (almost always!) it is better to go via the service. You could then put all your data access logic in the same place and only expose data through the service.

    Please remember to mark helpful posts as answer and/or helpful.

    • Marked as answer by g90 Wednesday, December 17, 2014 7:34 AM
    Tuesday, December 16, 2014 2:55 PM
  • In the past I've worked on web applications which had no web services, wcf or otherwise.

    These are regular asp.net apps.

    There are web pages read and write data to a database.

    Since this is asp.net the actual c# is running on a web server.

    From the web server they read and write data to a database using ado or entity framework.

    There is nothing inherently wrong with no web service at all if that's what you wanted to do.

    This approach is best suited to small -ish applications and probably intranet /extranet rather than end consumer web.

    If you're rewriting Amazon's inventory control system you will want something rather more sophisticated

    There are a lot more small to medium sized businesses with small to medium systems out there than there are huge companies.

    I would say this is still a pretty common architecture.


    Hope that helps
    Please don't forget to upvote posts which you like and mark those which answer your question.

    • Marked as answer by g90 Wednesday, December 17, 2014 9:24 AM
    Tuesday, December 16, 2014 3:41 PM
  • Thank you! I am concerned about displaying live the data. Is it possible with services every time there is a write to the database to automatically update values on the site? 
    Wednesday, December 17, 2014 9:26 AM
  • This is another question.

    You should really be starting a new thread per question.

    .

    If you want to show updates on a web page there are several issues.

    1)

    You need to know there's been a change.

    One mechanism.

    A trigger on each database table adds an entry to a table stating table y record x changed by user z change type I/U/D and a timestamp.

    Once you know what changed and when you need the clients to read that or a process to push those to the clients.

    Or

    The client needs to re-read their data regularly.  This is obviously inefficient but simple.

    2)

    The client needs to get that data and show it.

    You can do a page refresh with a meta tag which means the page reads the data again every 5 minutes or whatever.  That assumes you only have a few clients though and the page will actually refresh. 

    With WCF you can do something called a long poll.  google it. Gone out of favour now that jquery etc makes "code" on the client more practical.

    SignalR allows you to push data to the client.  This is what I'd usually use nowadays for this sort of requirement.  Google it.


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    • Marked as answer by g90 Thursday, December 18, 2014 7:33 AM
    Wednesday, December 17, 2014 9:51 AM
  • Thank you! I am concerned about displaying live the data. Is it possible with services every time there is a write to the database to automatically update values on the site? 

    Like clockwork for the last week and a half, I am up at 4:30 am. I don't know what is wrong, but I am going to talk with the family doctor.

    But anyway, it's not WCF the client or the service to do this. WCF job is to allow communications between the client and service by the means of using communication protocols like HTTP, Named Pipe, MSMQ and TCP/IP and the passing of data between the client and the service.  WCF is about SOA.

    http://en.wikipedia.org/wiki/Service-oriented_architecture

    http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF

    You need to understand Separation of concerns as to who is responsible for what.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wcf&prof=required

    <copied>

     A program that embodies SoC well is called a modular<sup class="reference" id="cite_ref-laplante_1-0">[1]</sup> program. Modularity, and hence separation of concerns, is achieved by encapsulating information inside a section of code that has a well-defined interface. Encapsulation is a means of information hiding.<sup class="reference" id="cite_ref-mitchell_2-0">[2]</sup> Layered designs in information systems are another embodiment of separation of concerns (e.g., presentation layer, business logic layer, data access layer, persistence layer).<sup class="reference" id="cite_ref-microsoft_3-0">[</sup>

    <sup class="reference" id="cite_ref-microsoft_3-0"><end></sup>

    http://en.wikipedia.org/wiki/Multitier_architecture

    MVP or MVC

    http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter<sup class="reference" id="cite_ref-microsoft_3-0"></sup>

    http://jobrocol.wordpress.com/2013/01/01/setting-up-an-n-tier-wcf-solution/

    UI

    MVP

    BLL

    Service Layer that consumes the WCF service, which is the client.

    WCF service

    The DAL sits behind the WCF service and does the CRUD with the database.

    DTO(s) are known by all layers the DTO(s) are in their own classlib project and all layers have reference to Entities (the classlib) project and know what the DTO(s) are about.

    The WCF client is one process and the WCF service is the other process.

    http://en.wikipedia.org/wiki/Data_transfer_object

    http://www.mindscapehq.com/documentation/lightspeed/Building-Distributed-Applications-/Building-WCF-Services-using-Data-Transfer-Objects

    You should learn how to use MVP and learn how to use the Service layer. The Srvice Layer consumes the WCF service

    http://polymorphicpodcast.com/shows/mv-patternsServ

    Service in the Service Layer that consumes the WCF service, and now I am going back to sleep.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using BLL.DTO;
    using Services.IServices;


    namespace Services
    {
        public class TheService1 : IService1
        {
            private static readonly TheService1 mInstance = null;

            public static TheService1 Instance
            {
                get { return mInstance; }
            }

            static TheService1()
            {
                mInstance = new TheService1();
            }

            public List<DTOAuthor> GetAuthors()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();

                try
                {
                    var dtoauthors = client.GetAuthors();
                    client.Close();

                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor()
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return authors;
            }

            public List<DTOAuthor> GetAuthorsWhere()
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();

                try
                {
                    var dtoauthors = client.GetAuthorsWhere();
                    client.Close();

                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return authors;
            }

            public List<DTOAuthor> SaveAuthors(List<DTOAuthor> auths)
            {
                var client = new WCFServiceReference.Service1Client();
                var authors = new List<DTOAuthor>();

                try
                {
                    var dtoauthors = client.SaveAuthors(auths.ToArray());
                    client.Close();

                    authors.AddRange(dtoauthors.Select(dtoauthor => new DTOAuthor
                    {
                        AuthorID = dtoauthor.AuthorID,
                        FirstName = dtoauthor.FirstName,
                        LastName = dtoauthor.LastName,
                        IsUpdate = dtoauthor.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return authors;
            }

            public DTOPayroll GetPayRollByAuthorID(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dtopayroll = new DTOPayroll();

                try
                {
                    dtopayroll = client.GetPayRollByAuthorID(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dtopayroll;
            }

            public void UpdatePayRollSalary(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
             
                try
                {
                    client.UpdatePayRollSalary(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOPayroll AddPayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOPayroll();

                try
                {
                    dto = client.AddPayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public void DeletePayRoll(DTOPayroll pr)
            {
                var client = new WCFServiceReference.Service1Client();

                try
                {
                    client.DeletePayRoll(pr);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }

            public DTOArticle GetArticleTop1()
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();
               
                try
                {
                    dto = client.GetArticleTop1();
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public DTOArticle GetArticle(int id)
            {
                var client = new WCFServiceReference.Service1Client();
                var dto = new DTOArticle();

                try
                {
                    dto = client.GetArticle(id);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return dto;
            }

            public List<DTOArticle> GetArticles()
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtos = client.GetArticles();
                    client.Close();

                    articles.AddRange(dtos.Select(dto => new DTOArticle
                    {
                        ArticleID = dto.ArticleID,
                        AuthorID = dto.AuthorID,
                        Title = dto.Title,
                        Body = dto.Body
                    }));
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

                return articles;
            }

            public List<DTOArticle> SaveArticles(List<DTOArticle> artcs)
            {
                var client = new WCFServiceReference.Service1Client();
                var articles = new List<DTOArticle>();

                try
                {
                    var dtoarticles = client.SaveArticles(artcs.ToArray());
                    client.Close();

                    articles.AddRange(dtoarticles.Select(dtoarticle => new DTOArticle()
                    {
                        ArticleID = dtoarticle.ArticleID,
                        AuthorID = dtoarticle.AuthorID,
                        Title = dtoarticle.Title,
                        Body = dtoarticle.Body,
                        IsUpdate = dtoarticle.IsUpdate
                    }).ToList());
                }
                catch (Exception ex)
                {
                    client.Abort();
                }

              return articles;
            }

            public void DeleteArticle(DTOArticle article)
            {
                var client = new WCFServiceReference.Service1Client();
         
                try
                {
                    client.DeleteArticle(article);
                    client.Close();
                }
                catch (Exception ex)
                {
                    client.Abort();
                }
            }
        }
    }

    Wednesday, December 17, 2014 10:39 AM