473,289 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Missing required element in serialized XML

I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix
82202, Visual studio .NET 2003 with hotfix 823639.
I have generated a proxy class using wsdl.exe from a schema that has an
xsd:date element called XYZ_IncDate.
<xsd:attribute name="XYZ_IncDate" type="xsd:date" use="required">
If I change the xsd:date element to be optional, then wsdl.exe generates two
attributes for the date field in the proxy class:

[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="date")]
public System.DateTime XYZ_IncDate;

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool XYZ_IncDateSpecified;
If the element is required, then it only generates one attribute.
[System.Xml.Serialization.XmlAttributeAttribute(Dat aType="date")]
public System.DateTime XYZ_IncDate;
The problem I am having is, when the element is required, it is not
serialized in the XML, and my web service request fails because this element
really is required, and it's not there. I can verify that that value is
being set in the proxy class, but it does not appear in the XML. When the
element is optional, I can force the attribute to appear in the XML by
setting the XYZ_IncDateSpecified to true, but I don't have that option in the
case where the attribute is required, because no XYZ_IncDateSpecified
attribute is created in the proxy.

It seems to me that the behavior in XML serialization for the case where the
element is required is exactly the opposite of what it should be. I can
understand not needing the XYZ_IncDateSpecified flag, because if it's
required it should always be serialized in the XML. But the opposite is
happening! It is never serialized in the XML, and you are not even given the
option to try to force it to serialize the value via the
XYZ_IncDateSpecified, as you can when it is optional. Is this a known bug in
XML serialization, and does anyone know what can be done to fix/work around
this without requiring manual editing of schema and proxy classes?

The trouble is, we need to have a solution that works for people who are
generating their XML schemas on the fly based on their data types - it is up
to their discretion whether certain attributes of their data are required or
not. Once they have created their datatype, we generate a schema which obeys
their wishes as far as whether certain elements are required or not, and we
create a wsdl referencing their schema for their data type. It's not just a
matter of tweaking one schema or one proxy class. We want to be able to have
users generate their schema and wsdl, generate the proxy, and run, without
having to do manual edits on the proxy class.

--
Cindy
May 13 '06 #1
3 5302
Hi Cindy,

Thank you for posting.

From your description, you're using .net framework to generate the
webservice client proxy for some webservice, and you're manually
constructing the WSDL document/xml schema for the service. However, you're
encountering some problem when generate the proxy class's property for a
date type attribute with use=required, correct?

Based on the code snippet and xml element definition you provided, I think
the .net generation code on the date type attribute is not only depend on
the "use" attribute in the xml schema, but also depend on the type in .net
framework which is used to represent the property/field of that xml
attribute. For Date type, .net framework will use the System.DateTime type
to represent it. However, since DateTime is a value type class(not
reference type), so any property/field of this type will always has a valid
instance on the variable, the property or field won't be null. That's why
when we set the xml attribute in schema as use="required", the generated
..net class field won't make any explicit change on it. And at runtime, you
can found even we don't assign any value to the Date property, there will
exists an instance on it. And only if the scheme type for the attribute is
set to use="optional" will the .net framework generate another field
(XXXSpecified) to indicate whether the value is null or not.....
This is the rule .net framework generate the property according to
property/attribute in webservice's WSDL doc.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


May 15 '06 #2
Yes, it is dependent on both the fact that the xsd:date type is mapped to a
ValueType and that it is required instead of optional. When I say in my
schema file that an element is "required", that logically means, regardless
of what type that element is, that it is must appear in the XML document, and
that without it the XML document is invalid. Therefore, when the XML is
serialized, the element and its value should always be included. On the
contrary, the behavior I see is that when the XML is serialized, no value
*ever* appears for this element, even though it is clear that the proxy class
has a valid value for the DateTime type set. I believe that this is a clear
bug in the XML serialization code.
--
Cindy
"Steven Cheng[MSFT]" wrote:
Hi Cindy,

Thank you for posting.

From your description, you're using .net framework to generate the
webservice client proxy for some webservice, and you're manually
constructing the WSDL document/xml schema for the service. However, you're
encountering some problem when generate the proxy class's property for a
date type attribute with use=required, correct?

Based on the code snippet and xml element definition you provided, I think
the .net generation code on the date type attribute is not only depend on
the "use" attribute in the xml schema, but also depend on the type in .net
framework which is used to represent the property/field of that xml
attribute. For Date type, .net framework will use the System.DateTime type
to represent it. However, since DateTime is a value type class(not
reference type), so any property/field of this type will always has a valid
instance on the variable, the property or field won't be null. That's why
when we set the xml attribute in schema as use="required", the generated
.net class field won't make any explicit change on it. And at runtime, you
can found even we don't assign any value to the Date property, there will
exists an instance on it. And only if the scheme type for the attribute is
set to use="optional" will the .net framework generate another field
(XXXSpecified) to indicate whether the value is null or not.....
This is the rule .net framework generate the property according to
property/attribute in webservice's WSDL doc.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights

May 15 '06 #3
Thanks for your response Cindy,

As for the following behavior:

=================
the behavior I see is that when the XML is serialized, no value
*ever* appears for this element,
====================

do you mean the SOAP message generated by the .net client proxy doesn't
contains attribute for the Date field? How are you getting the xml
serialized content. I've used some tracing tools to capture the SOAP
message of the webmethod , it seems that the .net runtime will generate
default value for the DateTime field event we do not explicitly set a
value. e.g:

<md1 Name="client name" Date="0001-01-01T00:00:00.0000000+08:00" />

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



May 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: richbl | last post by:
Hello all, I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For...
0
by: Lars | last post by:
Hello All, I have a question: is it possible to set the order of the elements of serialized object? Lets say we have Public Class Order Public Price As Decimal Private Quantity As Decimal...
4
by: Hollywood | last post by:
I'm using XML serialization to produce the following XML document: <TestDoc xmlns:srd="some-url"> <Additional> <Security> <srd:Login>login_id</srd:Login> <srd:Password>password</srd:Password>...
0
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ...
3
by: Samem N via DotNetMonster.com | last post by:
Does anyone know how to solve this error? I dont know where it went wrong. Any help would be appreciated .Thanks ERROR ______ Description: An unhandled exception occurred during the execution...
0
by: hdsj | last post by:
Hi All, Hoping someone can solve a problem for me. I am modifying the schema for a rather complex web service written in VB.NET. The services uses a large number of serialized classes to...
1
by: Eric | last post by:
Hi, I have a WS client. All the code is generated by VS.NET 2003. For me its seems that an attribute is not generated during sending the request in the SOAPHeader. The problem is with...
2
by: Alan Silver | last post by:
Hello, I'm getting an odd validation error from VWD. As I understand it, an opening ASP.NET for tag is supposed to look like... <form runat="server"> with an optional ID attribute. VWD...
2
by: inventor | last post by:
I'm doing programming for my science prodject, and when I was programming (I'm building an alphebatizer) I ran into this bug: I've got an input box, but no button or output box. so I do some...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.