473,555 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:attribut e name="XYZ_IncDa te" 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.Seri alization.XmlAt tributeAttribut e(DataType="dat e")]
public System.DateTime XYZ_IncDate;

/// <remarks/>
[System.Xml.Seri alization.XmlIg noreAttribute()]
public bool XYZ_IncDateSpec ified;
If the element is required, then it only generates one attribute.
[System.Xml.Seri alization.XmlAt tributeAttribut e(DataType="dat e")]
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_IncDateSpec ified to true, but I don't have that option in the
case where the attribute is required, because no XYZ_IncDateSpec ified
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_IncDateSpec ified 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_IncDateSpec ified, 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 5320
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.000 0000+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
5134
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 example, given: $data = serialize(array('4.50','0.00','0.00'));
0
1287
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 Public Readonly Property Total() As Decimal
4
2606
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> </Security> </Additional> </TestDoc>
0
1699
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). ---------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xs:schema id="TaskRequest" targetNamespace="http://xyz.com/TaskResponse/1.0"...
3
16276
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 of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
0
1196
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 output the overall XML. The problem I am having is that I require 2 XML elements of the same name to be serialized from the 1 class. Due to the way the...
1
3150
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 RFCSendingValue. There the attribute 'groupeid0 isn't generated in the SOAP request.
2
3653
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 gives me the following validation error...
2
498
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 reaserch, insert a button, and when I open it up, instead of the button being added, I lost the input box. Can ANYONE PLEASE HELP ME!!!!!!!!!!!!! I've...
0
7621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7542
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7824
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7587
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5170
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1156
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.