SOAP C# - Optional Properties

  • Thread starter Ian Jenkins, MCSD
  • Start date
I

Ian Jenkins, MCSD

How can you not require parameters in the WSDL of type DateTime, int,
double?

For example:

A DateTime field in a C# web service always serializes as:

<s:element minOccurs="1" maxOccurs="1" name="MyDateField"
type="s:dateTime" />

How does it have to be declared (or manipulated) in the C# code to end
up in the WSDL as:

<s:element minOccurs="0" maxOccurs="1" name="MyDateField"
type="s:dateTime" />
 
G

Guest

Hi Ian,

have you tried to use this?

....
public DateTime MyDateField;

[XmlIgnore]
public bool MyDateFieldSpecified;
....

George
 
I

Ian Jenkins, MCSD

George,
Your solution creates a property for my class that is not visible to
the web service. It does not change the minOccurs setting of the
MyDateField. I'm trying to set minOccurs="0" for MyDateField.
 
M

Marc Gravell

Try attributing with DefaultValue[Attribute] (in System.ComponentModel)

public class TestClass {
[DefaultValue(0)]
public int TestField;
private int _testPropField;
[DefaultValue(0)]
public int TestProperty {
get { return _testPropField; }
set { _testPropField = value; }
}
}

this gives:

<s:element minOccurs="0" maxOccurs="1" default="0" name="TestField"
type="s:int" />
<s:element minOccurs="0" maxOccurs="1" default="0" name="TestProperty"
type="s:int" />

Very close...

Marc
 

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