I am using wsdl.exe to convert a WSDL file and Types.xsd file into a C# file. The wsdl file specifies optional variables (minOccurs="0" maxOccurs="1"
), and the generated .NET type handles this by created two fields - one for the variable (e.g. status
) and one to let you know if it's specified (statusSpecified
).
Is there a way to use the wsdl
tool to only create one field that is Nullable
(i.e. if not null, it is specified)? (If it helps, I think I can change the wsdl file to have nillable="true"
elements.)
Is there a different, better tool that will generate .NET types from WSDL? I am using .NET 4, so it would be useful if the generated types took advantage of features like Nullable types.
NOTE: I just realized that I am using the wsdl tool from .NET 2 and that newer projects should use WCF for this stuff. Any pointers on the WCF way to get what I want?
Regarding WCF, this article pointed me in the direction of using the svcutil
tool (which was already in my PATH, so I could just run it from the command line in the folder with the wsdl and xsd files like so: svcutil *.wsdl *.xsd /language:C#
). Unfortunately, svcutil doesn't seem to do any better with using Nullable types instead of xSpecified
variables.
no, unless you modify your xsd schema. Read this article about xsd
If you have element with minOccurs="0"
and nillable="true"
it will still generate xSpecified field.
private System.Nullable<bool> x;
private bool xSpecified;
If you want field to be nullable then element in xsd needs minOccurs="1"
and nillable="true"
.
private System.Nullable<bool> x;
Difference between nullable and Specified:
<minzero xsi:nil="true"><minzero>
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With