svcutil and specified fields
I am generating a datacontract w开发者_如何学Cith svcutil from a webservice.
svcutil /language:cs /noConfig /targetclientversion:Version35
/out:Generated\ProductService.cs http://example.com/ProductService.svc?wsdl
The fields generated looks like this:
private System.Nullable<System.DateTime> createdField;
private bool createdFieldSpecified;
How can the fields be both nullable and have a specified field?
it depends on the source Wsdl. I bet there is something this (not sure of the syntax):
<xsd:element name="created" type="xsd:datetime" minOccurs="0" xsd:nil="true" />
svcutil.exe
use nillable
to produce a Nullable<>
field, and minOccurs
to produce a field + specified combination.
I also bet the WSDL is not a .Net generated WSDL !
The class generation is driven by XSD schema of the web service.
In order to generate nullable fields. The field should be marked as nillable
.
<xs:element minOccurs="0" maxOccurs="1" name="created" type="xs:dateTime" nillable="true" />
The XML will look like this.
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<created xsi:nil="true" />
</root>
I believe that this field in your schema looks like this:
<xs:element minOccurs="0" maxOccurs="1" name="created" />
and it would omit the element completely if createdFieldSpecified = false
:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</root>
The bottom line: web service schema should be updated in order to generate nullable fields with svcutil
.
精彩评论