Results 1 to 13 of 13

Thread: WCF Serialization

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    fgh
    Posts
    332

    WCF Serialization

    Hello,

    I have to develop a project which uses WCF and Dotnet Desktop application.

    I have a Dotnet Class Library (DBClassLib) which functions for database activities and database is placed on remote server.

    I need to create a WCF application (DBWCF) which calls the above said class library for database access.

    WCF application will be referenced in the Dotnet Desktop Application(DBClient).

    I have gone thru some topics on serialization.

    Consider in my project, i have to add the details of a Customer such as his id, name, address, zip etc..., and there is a method in DBClassLib project to do this. ClassName : CustomerEntity CE

    This class has created like to get fields as properties. CE.name, CE.address, etc...

    So from WCF application, i will create object for DBClassLib and set the values like said above.

    Now what i am having doubt is data transmission from Desktop and WCF app.

    I can create a method in wcf app {getCustName(name,address,...)} which accepts name, address, zip etc as method parameters and set to CE.Name = name, CE.address=address, etc.

    Is the above way is fast and perfect or

    Create a seperate class (WCFCustomerClass WCC) in WCF application which will have properties like name, address etc and in the desktop application, the user needs to set WCC.name="", WCC.address="",... and pass it as serialization technique.

    Which one is perfect in the above...

    thankzzzzzzz
    Last edited by sureshvijayan; Jul 16th, 2009 at 07:24 AM.
    gh

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: WCF Serialization

    Neither.... make your original class CustomerEntity, serializable and pass that as the parameter....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2002
    Location
    fgh
    Posts
    332

    Re: WCF Serialization

    Quote Originally Posted by techgnome View Post
    Neither.... make your original class CustomerEntity, serializable and pass that as the parameter....

    -tg
    The CustomerEntity class is serializable and in Client i tried to create an object of CustomerEntity, but its not working.

    [Serializable]
    CustomerEntity Class ==> [WCF application] ==> Client Program

    what i should do to create an object of Customer entity class in client. I dont want the client to provide dll of CustomerEntity Class. The client should access the WPF application and from there he could create the object of CustomerEntity class.

    what i am doing now is briefed in first post.


    {a seperate class (WCFCustomerClass WCC) in WCF application which will have properties like name, address etc and in the desktop application, the user needs to set WCC.name="", WCC.address="",... and in "WCFCustomerClass" again i will create an object of "DBClassLib" and set dbclasslibobject.name = wcfcustomerclassobject.name, like that..... so two times i need to work.}

    thankzzzzzzzz
    Last edited by sureshvijayan; Jul 17th, 2009 at 05:49 AM.
    gh

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: WCF Serialization

    In order to create of object of any kind on the client, the client has to have that object exist on the client.... the dll needs to be on the client, and on the server where the WCF app is located.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF Serialization

    Quote Originally Posted by techgnome View Post
    In order to create of object of any kind on the client, the client has to have that object exist on the client.... the dll needs to be on the client, and on the server where the WCF app is located.

    -tg
    Not strictly true - you dont need to have DLLs present on the client side. You can mark a class with the DataContract attribute on the WCF server side and then your client application can create instances of this class (assuming it has added a Service Reference to your WCF service) and it will be serialized automatically as long as it does not have any properties that use types that are not serializable or Read Only.

    Unless I am misunderstanding the question then this would be the best way to go. Make your CustomerEntity class on the WCF server side a DataContract and then your WCF client can just pass an instance of that class in as a parameter to the WCF service call

    Here's an example off the top of my head:

    Server Side:
    vb.net Code:
    1. <DataContract()> _
    2. Public Class CustomerEntity
    3.       <DataMember()> _
    4.        Public Property CustomerName As String
    5.        'Property implementation here
    6.        End Property
    7. End Class

    Client Side (after service reference has been added)
    vb.net Code:
    1. Dim CE As New MyWCFService.CustomerEntity
    2. CE.CustomerName = "John"
    3. 'etc etc

    Hope that helps
    Last edited by chris128; Jul 17th, 2009 at 10:58 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: WCF Serialization

    d'oh! ... Good call... that way if there are any changes, they are kept in synch... I forget about the Datacontract... my last foray into WCF had a bunch of things black boxed by our achitect... so some of the details like that were hidden from us.... :/

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF Serialization

    no worries I dont understand why anyone would ban the use of DataContracts but each to their own eh!

    Added an example to my previous post to make it clearer for the OP as well.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: WCF Serialization

    it's not that it was banned... it was one of those technical details that I "didn't need to worry about"..... he built it into the baseclass from which all things inherited, thusly black boxing the settings....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF Serialization

    Ohhh right sorry I thought you meant he banned you from using it. I would have thought even if its in the base class then you would at least want your developers to know what it is and how it works but what do I know
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: WCF Serialization

    agile programming... we were trying to do a 6 month project in 30 days.... and that was one of those things that's a Ron Popiel setting... "you set it and fuggetit"...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF Serialization

    None of the above (unless already stated).

    Create a class library with your entities in it. Have it referenced in both the desktop app as well as the WCF service. When you reference the WCF service in the desktop app, it will be smart enough to pick up your entities and serialize it to that type. This lets you preserve any logic that you may have added or will add inside your entity classes.

  12. #12
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF Serialization

    Quote Originally Posted by mendhak View Post
    None of the above (unless already stated).

    Create a class library with your entities in it. Have it referenced in both the desktop app as well as the WCF service. When you reference the WCF service in the desktop app, it will be smart enough to pick up your entities and serialize it to that type. This lets you preserve any logic that you may have added or will add inside your entity classes.
    Whats wrong with using a DataContract as I suggested? Isnt the entire purpose of a data contract to be used in situations like this?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF Serialization

    The DataContract will let you specify what's going back and the shape of what's going back (I want property1, property2, propety7 to be sent across the wire).

    But as in any business entity class, the property getters and setters may start introducing logic at some point and that's where DataContracts alone won't help. If you have the same classes on both sides, then you can preserve the logic, but the DataContract can let you specify exactly what goes across the wire - you may not need some properties to go across the wire because they are 'outcomes' of other properties or methods or constructors, etc.

    If you don't reference the classes on both sides, you get a 'stripped down' version of the original class and when new logic is introduced, you have to start converting to the new type and duplicating functionality.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width