Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

svcutil and specified fields

I am generating a datacontract with 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?

like image 244
adrianm Avatar asked Jun 14 '11 09:06

adrianm


People also ask

What is the use of svcutil?

This can be used to register system.serviceModel extensions without altering the tool's configuration file. Specifies the output to be generated by the tool. Valid values are code, metadata or xmlSerializer. Svcutil.exe can generate code for service contracts, clients and data types from metadata documents.

How to configure svcutil to provide metadata?

This can be defined either in the configuration file of Svcutil.exe, or in another configuration file specified using the /svcutilConfig option. The URL to a service endpoint that provides metadata or to a metadata document hosted online.

When does svcutil generate a configuration file for a service binding?

When the service binding is one of the system-provided bindings (see System-Provided Bindings ), and the ProtectionLevel property is set to either None or Sign, Svcutil generates a configuration file using the <customBinding> element instead of the expected system-provided element.

How do I start svcutil from a WCF service?

The WCF service must be running before the svcutil tool is started. The WCF service must expose its metadata using an HTTP port in addition to the WebSphere MQ custom channel endpoint references to generate a client directly from a running service. The custom channel must be registered in the configuration data for svcutil.


2 Answers

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 !

like image 158
Steve B Avatar answered Oct 17 '22 03:10

Steve B


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.

like image 1
Alex Aza Avatar answered Oct 17 '22 03:10

Alex Aza