wsdl.exe support for Nillable Value Types within WSDL

E

Erik Klein

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.
 
K

Kent Boogaart

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.
 
E

Erik Klein

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top