Svcutil and specified fields

I am creating a datacontract with svcutil from webservice.

svcutil /language:cs /noConfig /targetclientversion:Version35 /out:Generated\ProductService.cs http://example.com/ProductService.svc?wsdl 

Created fields look like this:

 private System.Nullable<System.DateTime> createdField; private bool createdFieldSpecified; 

How can fields be nullable and have a given field?

+6
source share
2 answers

it depends on the source of Wsdl. I am sure there is something (not sure about the syntax):

 <xsd:element name="created" type="xsd:datetime" minOccurs="0" xsd:nil="true" /> 

svcutil.exe use nillable to create the Nullable<> field and minOccurs to create the + field of the specified combination.

I also put that WSDL is not .NET-WSDL!

+6
source

Class generation is controlled by the XSD web service schema.

To create fields with a null value. The field should be marked as nillable .

 <xs:element minOccurs="0" maxOccurs="1" name="created" type="xs:dateTime" nillable="true" /> 

XML will look as follows.

 <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 completely drop the element if createdFieldSpecified = false :

 <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> </root> 

On the bottom line: the web service schema needs to be updated to generate fields with a null value using svcutil .

+1
source

Source: https://habr.com/ru/post/890485/


All Articles