SubSonic Forums
All Your Database Are Belong To Us

Passing data objects/collections to/from WCF

Latest post 11-18-2008 1:02 AM by guerven. 2 replies.
  • 11-06-2008 11:04 PM

    • ptutt
    • Not Ranked
    • Joined on 09-26-2008
    • Posts 4

    Passing data objects/collections to/from WCF

    I am using Subsonic as the DAL and want to share the subsonic data objects between the WCF service and a Windows client.  This does not appear to be possible.

    If I use Visual Studio 2008 to generate the client proxy it fails to use the "DataContractSerializer" and instead uses the XMLSerializer which then means that the shared objects will not be generated.

    If I use svcutil.exe as documented in http://www.codeproject.com/KB/WCF/WCFCollectionTypeSharing.aspx and force it to use the DataContractSerializer I get the following warnings:

    Warning: The optional WSDL extension element 'body' from namespace 'http://schemas.xmlsoap.org/wsdl/soap12/' was not handled. XPath: /wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WSHttpBinding_IService']/wsdl:operation[@name='GetData'] wsdl:output

    The problem seems to be related to the data objects being too complicated for the DataContractSerializer.  I could not find any indication of exactly why they fail.  The data objects should just contain the fields of the table as properties and that's it, but they contain a whole lot of other stuff.  Everything else should be in the controller class. I am using the repository record pattern.

    Has anyone found a way to share the dataobjects between the client and server via a WCF service?

    Filed under:
  • 11-07-2008 12:22 PM In reply to

    Re: Passing data objects/collections to/from WCF

    I think what you should do is create DTO's for transfering the objects

    If I am I because I am I, and You are You because You are You, then I am I, and you are you. But If I am I because You are You, and You are You because I am I, then I am not I and You are not You. -Rabbi of Kotzk

  • 11-18-2008 1:02 AM In reply to

    Re: Passing data objects/collections to/from WCF

         
        // this is in the interface
        [OperationContract]
        TBsampleTableCollection getSampleTableData(List<Where> whereCollection);



        // this is in the implementation
            public TBsampleTableCollection getSampleTableData(List<Where> whereCollection)
            {
                Query myquery = new Query(TBsampleTable);
                foreach (Where whereitem in whereCollection)
                    myquery.AddWhere(whereitem);
                IDataReader myReader = myquery.ExecuteReader();

                TBsampleTableCollection mycollection= new TBsampleTableCollection ();
                mycollection= .LoadAndCloseReader(myReader);
                return mycollection;
            }




            Using the default subsonic template. everything works fine except for nullable fields.
    XMLserialier and the default serialier cannot handle nullable types for attributes.This could be the problem you are facing with the DataContractSerializer.

     

    You must modiy the CS templates. and change the

    [XmlAttribute("<%=propName%>")]

    to

    [XmlElement("<%=propName%>")]

     

    OR you can change the template to use

    [DatacontractCollection] [DataContract] [DataMember]

    instead of the [Serializable] [XmlAttribute("<%=propName%>")]

     You also need to add

    using System.Runtime.Serialization;   to  CS_GeneratedScaffoledCodeBehind.aspx     // i think.Stick out tongue

     

     

    The Subsonic objets definitions that you are returning should be included in the ServiceProxy. no need to add subsonic to the consumer.

    Ofcourse you need to configure the Service correctly.

    But bottom line. It is possible to pass Subsonic Classes through WCF. .. that is what I believe.

     

     

    Filed under:
Page 1 of 1 (3 items) | RSS