Dino,
thanks for your reply!
We now added the "minOccurs" and "maxOccurs" settings into our WSDL-file and
updated the server- and client-classes. Now it works fine because it just
doesn't send the NULL-values to the client.
Previously we didn't specify these two attributes.
But, what if I absolutely don't have a chance to modify the server-WSDL?
Let's say that the attributes are specified like this:
<s:element name="Stamp" minOccurs="1" maxOccurs="1" type="s:date"
nillable="true" />
So I won't have a chance to consume this service the "easy" way!
I wonder why there is no functionality in the .NET serialization, which
supports something like
[XmlIgnore] public bool StampIsNull;
What do you think?
Max
"Dino Chiesa [Microsoft]" <dinoch@online.microsoft.com> wrote in message
news:uJPqDAXdEHA.3632@TK2MSFTNGP09.phx.gbl...[color=blue]
> There is a convention in .NET XML Serialization (which is used by the
> webservices runtime) that allows value-types to be marked as "nil".
> The convention is, for each property in a class with a name[/color]
"propertyName",[color=blue]
> if there is a companion property named "propertyNameSpecified" which is a
> bool, then the propertyNameSpecified indicates whether the property of[/color]
name[color=blue]
> "propertyName" is nil or not.
>
> See
>[/color]
http://msdn.microsoft.com/library/en...ClassTopic.asp[color=blue]
> for the doc on this.
>
> For example, this complexType in XML Schema:
> <s:complexType name="IdType">
> <s:sequence>
> <s:element name="Name" minOccurs="0" maxOccurs="1"
> type="s:string" nillable="true" />
> <s:element name="Stamp" minOccurs="0" maxOccurs="1"
> type="s:date" nillable="true" />
> <s:element name="Id" minOccurs="0" maxOccurs="1"
> type="s:int" nillable="true" />
> </s:sequence>
> </s:complexType>
>
> will generate something like this type definition in C#:
>
> [XmlType(Namespace="urn:myNameSpaceHere")]
> public class IdType {
> [XmlElement(IsNullable=true)] public string Name;
>
> [XmlElement(DataType="date")] public System.DateTime Stamp;
> [XmlIgnore] public bool StampSpecified;
>
> [XmlElement] public int Id;
> [XmlIgnore] public bool IdSpecified;
> }
>
> ---------
>
> Notice that the string (not a value type) is marked IsNillable=true, while
> the int and DateTime (both value types) are not. In your app code, to
> deal with nil values in the string, you do this:
>
> if (instance.Name != null) ...
>
> Conversely, to deal with nil values on value types (like the int and
> DateTime), what you need to do is
>
> if (instance.StampSpecified) ....
> if (instance.IdSpecified) ....
>
> The Id and Stamp will never actually be nil, but you treat them as nil in
> app code if the flag says that they are not specified. The same[/color]
convention[color=blue]
> applies to all value types in .NET.
>
> --------
>
> So, can you examine the generated files and tell me if you have the
> companion xxxSpecified properties marked "XmlIgnore"? If so, then you
> know what to do. . .
>
> -Dino
>
>
>
>
> "Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
> news:%23vwcyhTdEHA.3076@TK2MSFTNGP10.phx.gbl...[color=green]
> > Hello,
> >
> > I'd like to consume a WebService, which returns an array of objects[/color][/color]
which[color=blue][color=green]
> > include several members of type System.String, System.Decimal and
> > System.DateTime.
> > In the WSDL-file, the members of the object are marked as nilable.
> > I generated the client classes using VS.NET 2003. After the creation, I[/color]
> got[color=green]
> > the class-definition of the objects returned by the WebService too. BUT,
> > only the System.String members where marked to be nullable,[/color][/color]
System.Decimal[color=blue][color=green]
> > and System.DateTime don't. Ok, I know, they are value-types and cannot[/color][/color]
be[color=blue][color=green]
> > NULL, but thats exactly my problem.
> > If I then call the service, and it returns, I get an[/color]
> System.InvalidOperation[color=green]
> > exception.
> > If I change the datatypes of the decimal and datetime-members to
> > System.Object, everything works, but I have to do the value-conversion
> > myself.
> >
> > Is there a better way for solving that problem? I don't want to edit the
> > generated files everytime I regenerate them.
> >
> > Thanks very much!
> > Max
> >
> >[/color]
>
>
>[/color]