Nielsen's Weblog : .NET [use your Context dude]
Updated: 02-04-2007; 22:46:16.

 

Subscribe to "Nielsen's Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

2. april 2007

I think Microsoft did a great job with WCF, totally in love with this framework.

 

For years I have been using an xsd editor when designing my asmx messages, this is no different when choosing WCF as your favorite communication framework.

 

My frustration is when you design your xsd's and set the max occurs to unbounded on any simple type or complex type, the code generated by the svcutil sucks big time.

 

Take for instance this xsd:

 

<?xml version="1.0" encoding="utf-16"?>

<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://datacontract/2007/03/OrderMessage" elementFormDefault="qualified" targetNamespace="http://datacontract/2007/03/OrderMessage" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="OrderMessage" nillable="true" type="OrderMessage" />

  <xs:complexType name="OrderMessage">

    <xs:sequence>

      <xs:element minOccurs="1" maxOccurs="unbounded" name="Items" nillable="true" type="LineItems" />

    </xs:sequence>

  </xs:complexType>

  <xs:element name="LineItems" nillable="true" type="LineItems" />

  <xs:complexType name="LineItems">

    <xs:sequence minOccurs="1" maxOccurs="1">

      <xs:element name="total" type="xs:decimal" />

      <xs:element name="description" type="xs:string" />

    </xs:sequence>

  </xs:complexType>

  <xs:element name="OrderMessageReply" type="OrderMessageReply" />

  <xs:complexType name="OrderMessageReply">

    <xs:sequence>

      <xs:element name="Confirmed" type="xs:boolean" />

    </xs:sequence>

  </xs:complexType>

</xs:schema>

 

When generating code using svcutil.exe /dconly schema1.xsd it produces this code here:

 

Garbage omitted here for clarity J

 

public class OrderMessage : List<LineItems>

{

}

   

public partial class LineItems : object, IExtensibleDataObject

{

 

WTF, this is clearly not what I wanted, give me this structure here !!:

          

public class OrderMessage : object, IExtensibleDataObject

{

      public List<LineItems> LineItems;

}

 

What can you about this ?.

 

Apparently there is this ArrayOfxxxx convention, a convention first seen in the wsdl 1.1 specification, later abandond by the WS-BP and then gladly introduced again in the svcutil.exe, oh joy, what a great interoperability message the world here got from the WCF team J.

 

You can overcome this by introducing in your xsd's a complex type called ArrayOfLineItems and then create an element of type LineItems and then you would set the max occurs to unbounded. In your OrderMessage you would then create an element of type ArrayOfLineItems.

 

Great eh!!, this sure will put an extra burden on how you would organize your xsd's in the future.

 

This is not just about your custom complex types, oh no this goes for all the simple types also!!, so putting max occurs > 1 on a simple string type would mean you would have to create an ArrayOfstring.

 

That simply sucks, agree.

 

Your only option is to go with xsd.exe. That equally messed up code generator which has no support for System.Collections.Generic.List and friends, no support for Guids, Uri and the like.

 

Say you can live with xsd.exe!!!, you would then use the [XmlSerializerFormat]

which you can use on the interface, operation and on a class also.

 

[XmlSerializerFormat]

[ServiceContract(Namespace = "http://testservice/2007/03/service")]

public interface IService

{

       [OperationContract]

       OrderMessageReply CreateOrder(OrderMessage message);

}

 

This will instruct the serializer to use the xmlserializer instead of the datacontractserializer when performing marshalling of your messages.

 

I just hate this, I take a 10% performance loss when using the XmlSerializer and the fact that I am still stuck with xsd.exe is just bad karma.

 

What are the BTS team doing about this. BTS R2 will have support for WCF, are you telling me these guys will gladly accept this crap code from svcutil ???, I think not, so I take some comfort in believing that this will be corrected this year and the person who introduced this tedious nameing convention in svcutil.exe is promoted to VB 6.0 program manager in Sibiria.

 

"The most difficult thing in the world is to know how to do a thing and to

watch someone else do it wrong, without comment."

   --Theodore H. White

 


10:41:54 PM    comment []

© Copyright 2007 Allan Nielsen.



Click here to visit the Radio UserLand website.
 


April 2007
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Mar   May