none
WCF service for collection XML data RRS feed

  • Question

  • Dear all,

    I need to build a WCF service which will provide to an aplpication data fro an XML file.
    The data collection from the XML file is as follow :

    <GOODS>
     <GOOD>
      <CODE>6040-01</CODE>
      <TYPE_OFFRE>2</TYPE_OFFRE>
      <CODE_SITE>01</CODE_SITE>
      <NO_ASP>1855999</NO_ASP>
      <NO_DOSSIER>00064</NO_DOSSIER>
      <NO_MANDAT>075</NO_MANDAT>
     </GOOD>
     <GOOD>
      <CODE>6040-02</CODE>
      <TYPE_OFFRE>3</TYPE_OFFRE>
      <CODE_SITE>02</CODE_SITE>
      <NO_ASP>1855985</NO_ASP>
      <NO_DOSSIER>00065</NO_DOSSIER>
      <NO_MANDAT>076</NO_MANDAT>
     </GOOD>
    
     .....
    </GOOD>

    In the file above the number items in the collection if  <GOODS>  can be over 400 items.

    I have never build a WCF service based on XML source file , I was more doing it with database, so I was wondering if any could guide me a bit on the approach to build in order to collect them efficiently and build the data layer correctly

    - How build the WCF interface to be able to querry the XML file ?
    - How to querry efficently the XML itesm in order to collect correct info ?

     For exemple GetCompanyInfo() should return items <CODE>,<CODE_SITE>,<NO_ASP>

    Any sample will help a lot to start

    Thnaks for help
    regards

     

     


    Your knowledge is enhanced by that of others.
    Friday, October 1, 2010 3:09 PM

Answers

  • Hi Serge,

    For your WCF service client(the consumer), is it possible to directly get raw XML document as service response? If so, you can directly return XmlElement(or XElement) type in your WCF service operation.


    #How to return XML from WCF Service and Consuming from the client
    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/90716451-fd29-4917-a5ca-f7f3bcaa96c9

    As for how to read and manipulate(query , filtering) data from the xml file, I think it depends whether you care about the memory consumption on the server. If memory pressure is not big problem, the LINQ 2 XML(or XmlDocument) based API is very good choice for manipulating XML document. Otherwise, you can consider using the Xmlreader based approach which will not cache the entire xml document in memory and use an event based model to access XML document.

    #Reading XML with the XmlReader
    http://msdn.microsoft.com/en-us/library/aa720470(VS.71).aspx

    #Chapter 9 — Improving XML Performance
    http://msdn.microsoft.com/en-us/library/ff647804.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Mog Liang Friday, October 8, 2010 6:22 AM
    Tuesday, October 5, 2010 7:32 AM
    Moderator

All replies

  • It depends how the client needs to work.

    As a programming model it is probably better to create the classes which the xml represents:

    class Good

    {

    string code;

    string type_offre;

    ...

    }

    then return to the client List<Good>.

    If the request is too large you may use streaming or create paged operations:

    void GetGoods(startPage, endPage)


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Friday, October 1, 2010 4:12 PM
  • Ok but how to return the data I want from the XML file, XPATH or stuff like that;

    How to do to the SELECT <CODE>,<CODE_SITE>,<NO_ASP> FROM GOOD in teh XML file ?


    Your knowledge is enhanced by that of others.
    Friday, October 1, 2010 8:18 PM
  • If the file is not too big you can load it all to your List<Good> and then do filtering in code.

    If the file will be big then use Linq2Xml:

    http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

    Xpath is also an option.

     

    Now you can add more caching tricks, for example if the xml does not change much you can load it once to a data member which is shared between all calls and save the overhead of reading from file all the time. You would need to handle concurrency and such by yourself though.

     

    Not sure how cost effective it is for your project but today there are some "xml databases" (nosql) where you can store your data in and query. MongoDB and RavenDB are some examples.

     


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Friday, October 1, 2010 8:48 PM
  • IN my XML file, each item as a 108 element, so the GOOD class will have 108 properties matching element field

    So total the XML file is 400 GOODS with 108 element each

    based on that size, what will you suggest them ?


    Your knowledge is enhanced by that of others.
    Saturday, October 2, 2010 1:01 PM
  • Have you considered the possibility of putting xml data into the database? This will make it a lot easeir for you to query the data you need for each call since you have already done it with databeses before.

    kr

    Saturday, October 2, 2010 3:02 PM
  • Use linq2xml to query the data. Decide if you cache it or not based on the total size of the objects and the server.


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Saturday, October 2, 2010 6:13 PM
  • Hi Serge,

    For your WCF service client(the consumer), is it possible to directly get raw XML document as service response? If so, you can directly return XmlElement(or XElement) type in your WCF service operation.


    #How to return XML from WCF Service and Consuming from the client
    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/90716451-fd29-4917-a5ca-f7f3bcaa96c9

    As for how to read and manipulate(query , filtering) data from the xml file, I think it depends whether you care about the memory consumption on the server. If memory pressure is not big problem, the LINQ 2 XML(or XmlDocument) based API is very good choice for manipulating XML document. Otherwise, you can consider using the Xmlreader based approach which will not cache the entire xml document in memory and use an event based model to access XML document.

    #Reading XML with the XmlReader
    http://msdn.microsoft.com/en-us/library/aa720470(VS.71).aspx

    #Chapter 9 — Improving XML Performance
    http://msdn.microsoft.com/en-us/library/ff647804.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Mog Liang Friday, October 8, 2010 6:22 AM
    Tuesday, October 5, 2010 7:32 AM
    Moderator