locked
Class Vs Structure Implementation WCF RRS feed

  • Question

  • Hello All,

    What advantages does a class offer over using a structure? Is it true that Structs are more efficient and more web service interoperable than classes?

    The web service that I am developing is going to get consumed by many other non-.net applications. So, the data types must get serialized that are supported by HTTP to ensure max. interoperability. Does the usage of Structures instaed of Classes will ensure this OR using classes will not harm this ?

    With what shall I go with?

    Thanks in advance,


    AT



    • Edited by Alex Cardo Tuesday, May 8, 2012 2:50 PM
    Monday, May 7, 2012 9:42 AM

Answers

  • AFIK Peoplesoft Can consume WCF service(BasicHttpBinding) aligned with SOAP1.2. Another way of making sure about interoperability is of using WCF REST.Beacuse,

    In terms of platforms, REST has the advantage because all you need to use REST is an HTTP stack (either on the client or the server). Since almost every platform and device has that today, I would argue that REST has the widest interoperability. Given that mobile devices, household devices, POS devices, DVD players, and TVs all have Internet connectivity, there are more and more platforms for which having a full SOAP toolkit is impossible or unlikely. And even if you do have a SOAP toolkit for a particular platform, the chance of it working with another platform's implementation is not 100% So you can think of using WCF REST.


    Lingaraj Mishra

    Wednesday, May 9, 2012 9:39 AM

All replies

  • On 5/7/2012 5:42 AM, Alex Cardo wrote:
    > Hello All,
    >
    > What advantages does a class offer over using a structure? Is it true
    > that Structs are more efficient and more web service interoperable than
    > classes?
    >
    > With what shall I go with?
    >
     
    A class can be xml serialized by WCF by using the Serializeable
    attribute on the class and Datamember attributes on primitive
    properties. A class can have behavior when cast back to a known type.
     
    I have written many Web services legacy and WCF. I have never seen a
    Stuck used, because I need the class/object to have behavior on the
    client and service sides. And I have large amounts of data and objects
    classes (graphs) within a class/object. Those objects are like little
    machines
     
     
    I guess you can use a struck for small amounts of data that is not
    complicated.
     
     
    Monday, May 7, 2012 12:27 PM
  • A general characteristic of defining structure lies with below rules.

    • It logically represents a single value, similar to primitive types (integer, double, and so on).
    • It has an instance size smaller than 16 bytes.
    • It is immutable.
    • It will not have to be boxed frequently.

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

    But in WCF worlds it does not matter whether it is a Structure or Class. But if you are going to constructs hierarchical object models then class is preferable.  Whatever you prefer but make sure that you are exposing Interoperable .net types.  For example Data Type Interoperability between .NET and Java is,

    Do you have any idea about the non .net application's platform. Interoperability study between Web Services built with .NET Framework 4 with Java, Oracle Web logic, IBM Web Sphere and Oracle Metro is posted here.

    http://msdn.microsoft.com/en-us/netframework/webservicesinterop.aspx


    Lingaraj Mishra


    • Edited by Lingaraj Mishra Tuesday, May 8, 2012 5:04 AM
    • Marked as answer by Alex Cardo Wednesday, May 9, 2012 6:39 AM
    • Unmarked as answer by Alex Cardo Wednesday, May 9, 2012 6:42 AM
    Tuesday, May 8, 2012 5:00 AM
    • Marked as answer by Alex Cardo Wednesday, May 9, 2012 6:39 AM
    • Unmarked as answer by Alex Cardo Wednesday, May 9, 2012 6:42 AM
    Wednesday, May 9, 2012 6:38 AM
  • The non .net applications would be Peoplesoft applns

    AT

    Wednesday, May 9, 2012 6:41 AM
  • AFIK Peoplesoft Can consume WCF service(BasicHttpBinding) aligned with SOAP1.2. Another way of making sure about interoperability is of using WCF REST.Beacuse,

    In terms of platforms, REST has the advantage because all you need to use REST is an HTTP stack (either on the client or the server). Since almost every platform and device has that today, I would argue that REST has the widest interoperability. Given that mobile devices, household devices, POS devices, DVD players, and TVs all have Internet connectivity, there are more and more platforms for which having a full SOAP toolkit is impossible or unlikely. And even if you do have a SOAP toolkit for a particular platform, the chance of it working with another platform's implementation is not 100% So you can think of using WCF REST.


    Lingaraj Mishra

    Wednesday, May 9, 2012 9:39 AM