PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.

wsdl.exe support for Nillable Value Types within WSDL

 
 
Erik Klein
Guest
Posts: n/a
 
      10th May 2004
I have a WebService whose WSDL contains the following snippet:

<complexType abstract="true" name="Type">
<sequence>
<element name="localId" nillable="true" type="xsd:string"/>
<element name="id" minOccurs="0" maxOccurs="1" nillable="true"
type="xsd:int"/>
</sequence>
</complexType>

When I run wsdl.exe against this, the following C# code is generated:

public abstract class Type {
public string localId;
public int id;
}

Unfortunately, the "id" element is incapable of holding null / nil
values because it is a Value Type (int). If the client specifies
nothing, the value sent is zero(0) which is incorrect and violates the
XML Schema.

I will be providing this WSDL to my clients ... they will be building
their own Web Service Clients using tools including wsdl.exe.

How do I workaround wsdl.exe's apparant "lack of support" for
'nillable="true"' and 'minOccurs="0"'?

Thanks in advance.
 
Reply With Quote
 
 
 
 
Kent Boogaart
Guest
Posts: n/a
 
      12th May 2004
One solution (the one I took) is to manually alter the generated code to use
an object reference rather than a value type:

public class Type {
public string localId;
public object id;
}

Obviously you'll have to cast where not null. You could also maybe use the
types defined in System.Data.SqlTypes which are nillable.

HTH,
Kent

A nicer solution would be for wsdl.exe to do this for you. I'm not sure if
there are plans to fix this in future .NET releases.

"Erik Klein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a WebService whose WSDL contains the following snippet:
>
> <complexType abstract="true" name="Type">
> <sequence>
> <element name="localId" nillable="true" type="xsd:string"/>
> <element name="id" minOccurs="0" maxOccurs="1" nillable="true"
> type="xsd:int"/>
> </sequence>
> </complexType>
>
> When I run wsdl.exe against this, the following C# code is generated:
>
> public abstract class Type {
> public string localId;
> public int id;
> }
>
> Unfortunately, the "id" element is incapable of holding null / nil
> values because it is a Value Type (int). If the client specifies
> nothing, the value sent is zero(0) which is incorrect and violates the
> XML Schema.
>
> I will be providing this WSDL to my clients ... they will be building
> their own Web Service Clients using tools including wsdl.exe.
>
> How do I workaround wsdl.exe's apparant "lack of support" for
> 'nillable="true"' and 'minOccurs="0"'?
>
> Thanks in advance.



 
Reply With Quote
 
 
 
 
Erik Klein
Guest
Posts: n/a
 
      12th May 2004
Thanks for the suggestions.

I have already modified the code to use object instead of int.
Unfortunately, that eliminates the whole purpose for me specifying "int"
in the WSDL in the first place ... I wanted strict type casting. That
is now gone.

<< You could also maybe use the
types defined in System.Data.SqlTypes which are nillable.>>

Regrettably, these are not Serializable and therefore .NET can't
transmit them as XML to a Web Service.

<<A nicer solution would be for wsdl.exe to do this for you.>>

I personally believe that a "nicer solution" would be for Dot-Net to
join the rest of the world in recognizing the need for unspecified
values within Value Types. It might also be nice for them to abide by
the WSDL/XML Schema standard for 'nillable="true"' within a type.

Thanks for your help.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Microsoft Excel Charting 17 12th May 2010 06:51 PM
XmlSerialzer error when multiple nillable elements of userdefined =?Utf-8?B?a3Jpc2huYQ==?= Microsoft C# .NET 0 9th Nov 2007 08:23 PM
why does ado .net ignore nillable property when I set it? Scott Emick Microsoft ADO .NET 0 21st Sep 2004 08:17 PM
Help: VS2003 BUG? - Boxed value types cannot be casted to custom value types Laura T. Microsoft C# .NET 3 15th Jul 2004 04:23 PM
wsdl.exe and Nillable Value Types Erik Klein Microsoft Dot NET Framework 0 4th May 2004 04:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:29 PM.