The Artima Developer Community
Sponsored Link

.NET Buzz Forum
The Web services empire strikes back - Code generation: properties instead of fields

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christian Weyer

Posts: 616
Nickname: cweyer
Registered: Sep, 2003

Christian Weyer is an independent Microsoft MSDN Regional Director and expert for Web services.
The Web services empire strikes back - Code generation: properties instead of fields Posted: Dec 28, 2004 4:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Christian Weyer.
Original Post: The Web services empire strikes back - Code generation: properties instead of fields
Feed Title: Christian Weyer: Web Services & .NET
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/cweyer/Rss.aspx
Feed Description: Philosophizing about and criticizing the brave new world ...
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Christian Weyer
Latest Posts From Christian Weyer: Web Services & .NET

Advertisement

Part 1: The Web services empire strikes back - Introductory thoughts
Part 2: The Web services empire strikes back - Inner Workings
Part 3: The Web services empire strikes back - Web Services in Visual Studio 2005
Part 4: The Web services empire strikes back - WS-I BP Conformance
Part 5: The Web services empire strikes back - Custom XML Serialization
Part 6: The Web services empire strikes back - Proxy Type Sharing
Part 7: The Web services empire strikes back - Contract-first with .NET 'IDL'
Part 8: The Web services empire strikes back - Schema Importer Extensions
Part 9: The Web services empire strikes back - Making asynchronous Web service calls easier
Part 10: The Web services empire strikes back - Support for Nullable and SqlTypes
Part 11: The Web services empire strikes back - Support for Generics
Part 12: The Web services empire strikes back - Web services and large content [link]

A small but nice and very powerful new feature is intrinsic to the proxy generation process, again. I cannot count the number of emails and newsgroups postings I have read and answered regarding this problem. The standard proxy generation process in the 1.x version of the .NET Framework always emits public fields for complex types found in the service’s message contract’s data structures. This is of course a big disadvantage, at least when it comes to data binding – have you ever tried to bind Windows Forms controls to public data fields?

Version 2 now automatically and by default generates private fields encapsulated by public properties. This is a big win. The following code listing is the OrderStatusInfo class we have been talking a few times in former posts.

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(
  Namespace="
http://www.thinktecture.com/demos/Orders")]
public class OrderStatusInfo {
   
    private int orderNumberField;
   
    private System.DateTime orderDateField;
   
    private System.DateTime shipDateField;
   
    /// <remarks/>
    public int OrderNumber {
        get {
            return this.orderNumberField;
        }
        set {
            this.orderNumberField = value;
        }
    }
   
    /// <remarks/>
    public System.DateTime OrderDate {
        get {
            return this.orderDateField;
        }
        set {
            this.orderDateField = value;
        }
    }
   
    /// <remarks/>
    public System.DateTime ShipDate {
        get {
            return this.shipDateField;
        }
        set {
            this.shipDateField = value;
        }
    }

Finally we have the desired behavior that makes data binding a breeze. And for those of you paying attention to the above code, you might have realized an additional attribute that can save a lot of people a lot of work: System.SerializableAttribute. This means that now by default our types are not only XML serializable by using the XmlSerializer but also runtime serializable by using one of the runtime formatters like SoapFormatter or BinaryFormatter.

To sum up all the new and important switches of wsdl.exe that have been introduced in this short overview, you can take a look at the following table.

Switch

Description

sqltypes

Generate SqlTypes for nillable primitive elements. The switch cannot be used with /server.

sharetypes

Turns on Proxy Type Sharing feature.

verbose

Displays extra information in the case /sharetypes switch were specified.

fields

Generate fields instead of properties.



Table: Important wsdl.exe switches

BTW, if you want or need those features, i.e. public fields and [Serializable] types - already with .NET 1.x you can try the WSCF tool.

Read: The Web services empire strikes back - Code generation: properties instead of fields

Topic: VS2005 Dec CTP Team Edition is a No Go Previous Topic   Next Topic Topic: CMS / MSIB plus pack - source code available

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use