codegen:nullValue Still not working for me

M

mklapp

Hello,

I have a Web service retrieving data from SQL Server
2000 and returning rows which contain a DBNull in a
field. I have modified the XML Schema according to an
MSDN article, a KB article and a fellow poster.
Still I am crashing.

I created a test app, according to a KB article
designed to demonstrate this capability. Exploring that
project I discovered the Class routines behind the
dataset. Thes routines were addressing a column named
_Region whereas the Customers table for the Northwind
database only has a column named Region (without the
leading underscore).
Must the name of the 'nullable' column being tested
have a leading underscore?

My schema is included below for reference.

Thank you,

mklapp

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="MASpedDataSet" xmlns:codegen="urn:schemas-
microsoft-com:xml-msprop"
targetNamespace="http://www.tempuri.org/MASpedDataSet.xsd"

attributeFormDefault="qualified"
elementFormDefault="qualified"
xmlns:mstns="http://www.tempuri.org/MASpedDataSet.
xsd" xmlns="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="MASpedDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="MASped">
<xs:complexType>

<xs:sequence>

<xs:element name="StudentId" codegen:nullValue=""
type="xs:string" />

<xs:element name="MASpedId" codegen:nullValue="0"
type="xs:int" />

<xs:element name="MANumber" codegen:nullValue=""
type="xs:string" />

<xs:element name="MAStatus" codegen:nullValue=""
type="xs:string" minOccurs="0" />

<xs:element name="MCHIP" codegen:nullValue=""
type="xs:string" minOccurs="0" />

<xs:element name="PrimeIns" codegen:nullValue="0"
type="xs:int" minOccurs="0" />

<xs:element name="ServicesCovered"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="SecondaryIns"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="MACDocPhone"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="MACDocNumber"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="MACDocApprove"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="OtherFirstName"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="OtherLastName"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="OutOfCounty"
codegen:nullValue="" type="xs:string" minOccurs="0" />

<xs:element name="DateStamp" type="xs:dateTime"
minOccurs="0" />

<xs:element name="BusRider" codegen:nullValue="N"
type="xs:string" minOccurs="0" />

<xs:element name="UserId" codegen:nullValue=""
type="xs:string" minOccurs="0" />

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1"
msdata:primaryKey="true">
<xs:selector
xpath=".//mstns:MASped" />
<xs:field
xpath="mstns:StudentId" />
</xs:unique>
</xs:element>
</xs:schema>
 
M

mklapp

I see that the underscore for "Region" is because Region
is a reserved word.

The code behind both datasets (Mine and the working
example) is essentially identical (excluding column names
unique to each dataset). I can see where the null should
be converted to the replacement value, however, given
that nulls are not replaced, the two sets of code are
eithed not being executed in the same way, or the code
for my dataset is not being seen and/or executed.

mklapp
 
K

Kathleen Dollard

mklapp,

I don't see code gen as a valid namespace prefix in your XSD. Did I overlook
something?

What do you mean by "crashing" The more specifics you can give on that, the
more likely someone can help you.

Kathleen
 
M

mklapp

The codegen namespace is split across the 3rd and 4th
lines :

xmlns:codegen="urn:schemas-
microsoft-com:xml-msprop"

The crash occurs when the DBNull value is moved to the
TextControl Property. It is a null value exception. I
know I can Procedurally filter out the Null with an iif,
but, if a more robust and less obtrusive method is
available and reliable (and documented), then I want to
deliver it to the client. Given the sprawling nature of
this legacy app, anything other than using the nullValue
annotation is third best.

Mklapp
 
M

mklapp

Hello and Thanks for the follow-up,

I have looked at this problem for a little bit so far
(I must deal with it one way or tyhe other).

When I gen the dataset and modify the XML to include
the codegen:nullValue statements, I can see the code-
behind page for the dataset and I see the properties have
the correct code to return the coorect value. If the
application it is a part of is the only app to use it,
then all is well, the 'default' non-null values appear.

However, these datasets are defined in a web service.
When the web service returns the dataset to the client
app, it appears as though the dataset now uses code-
behind the Web Reference in the client app and this code
does not have the checks for nullValue.

All of the adapters and datasets were generated using
the appropriate wizard and none of the datasets are on
the Designer (but all are a part of the Web Service).

I have compared the dataset example in the KB article
and the one I am using. There is no difference in the
property code, until I look at the Web reference code in
my client App.

It looks as though I may have a few options:

1: modify the code behind the Web Reference - This is
asking for trouble. As soon as I update the web
reference, all my changes would be wiped and I would have
to do themn all over again.

2: Receive a fix from MS so that the Web Ref code
reflects the XML Schema. (No reflection on MS, but I do
not think that will happen for me in a timely manner)

3: Maintain duplicate dataset objects (set of files),
one for the Web Service and one for the Client App. I
have tried this in a limited test and did not seem to get
the desired results. Even if I did, I would be hard
pressed to justify maintaining two separate sets of
identical objects just to keep from writing 1500 IIf
statements.

4: Write 1500 IIF statements.

5: Define all the datasets in the client app, have the
web service maintain a web reference to the client. I
would try this for this app (only) because it will be
static over time and the functionality is nicely isolated
from the rest of the system. The problems are : 1, it
might not work; 2, I have fifty datasets - it will be
quicker to write 1500 IIF statements; 3, it just seems
like a bad idea.

So, that is it in a nutshell. I believe this
eliminates the need to compare property code between the
KB example and my code (although I could be wrong).

If I have to wait a time for a fix, then I can wait a
while. If it is too long a wait, I need to get started
with the IIFs.

Thank you for your interest,

mklapp
 
K

Kevin Yu [MSFT]

Hi mklapp,

Have you tried to regenerate the strongly typed dataset class by right
clicking the dataset XSD file in the solution explore and choose "Run
Custom Tool" from the popup menu.

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

mklapp

The classes directly associated with the .xsd file (in
the web service) are good (in that they do what is
desired : return a non-null 'default' value). The
problem seems to lie in the code behind the web reference
for the client App. The only null detection in that code
is indirect. In the Property, the value is assigned or
returned and an invalid cast exception is handled with a
dialog box.


mklapp

(Yes, I tried regenning the XSD this morning and updated
the web ref as well. No change, but thanks)
 
K

Kevin Yu [MSFT]

Hi mklapp,

Would you please try to save the schema of the typed dataset and check if
the nullValue attribute is in the exported file?

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

mklapp

Hello,

That is easy to answer.
No it does not. If I invoke the WriteXMLSchema method
for the dataset (Or whatever method outputs the schema),
the codegen items, namespece, nulValues, etc, are not
there.
The below is the retrieved schema: (Sorry for the
mess). Below it is the Schema in the dataset itself,
visible in the IDE designer:

<?xml version="1.0" standalone="yes"?>
<xs:schema id="MASpedDataSet"
targetNamespace="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns:mstns="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="MASpedDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="MASped">
<xs:complexType>
<xs:sequence>
<xs:element name="StudentId"
type="xs:string" />
<xs:element name="MASpedId" type="xs:int" />
<xs:element name="MANumber"
type="xs:string" />
<xs:element name="MAStatus"
type="xs:string" minOccurs="0" />
<xs:element name="MCHIP" type="xs:string"
minOccurs="0" />
<xs:element name="PrimeIns" type="xs:int"
minOccurs="0" />
<xs:element name="ServicesCovered"
type="xs:string" minOccurs="0" />
<xs:element name="SecondaryIns"
type="xs:string" minOccurs="0" />
<xs:element name="MACDocPhone"
type="xs:string" minOccurs="0" />
<xs:element name="MACDocNumber"
type="xs:string" minOccurs="0" />
<xs:element name="MACDocApprove"
type="xs:string" minOccurs="0" />
<xs:element name="OtherFirstName"
type="xs:string" minOccurs="0" />
<xs:element name="OtherLastName"
type="xs:string" minOccurs="0" />
<xs:element name="OutOfCounty"
type="xs:string" minOccurs="0" />
<xs:element name="DateStamp"
type="xs:dateTime" minOccurs="0" />
<xs:element name="BusRider"
type="xs:string" minOccurs="0" />
<xs:element name="UserId" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1"
msdata:primaryKey="true">
<xs:selector xpath=".//mstns:MASped" />
<xs:field xpath="mstns:StudentId" />
</xs:unique>
</xs:element>
</xs:schema>

This is What I have defined in the XSD file. Note the
codegen references :

<?xml version="1.0" standalone="yes"?>
<xs:schema id="MASpedDataSet"
targetNamespace="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"
xmlns:mstns="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns="http://www.tempuri.org/MASpedDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="MASpedDataSet"
msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="MASped">
<xs:complexType>

<xs:sequence>

<xs:element name="StudentId"
codegen:nullValue=" " type="xs:string"/>

<xs:element name="MASpedId" codegen:nullValue="0"
type="xs:int"/>

<xs:element name="MANumber" codegen:nullValue=" "
type="xs:string"/>

<xs:element name="MAStatus" codegen:nullValue=" "
type="xs:string" minOccurs="0"/>

<xs:element name="MCHIP" codegen:nullValue=" "
type="xs:string" minOccurs="0"/>

<xs:element name="PrimeIns" codegen:nullValue="0"
type="xs:int" minOccurs="0"/>

<xs:element name="ServicesCovered"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="SecondaryIns"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="MACDocPhone"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="MACDocNumber"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="MACDocApprove"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="OtherFirstName"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="OtherLastName"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="OutOfCounty"
codegen:nullValue=" " type="xs:string" minOccurs="0"/>

<xs:element name="DateStamp" type="xs:dateTime"
minOccurs="0"/>

<xs:element name="BusRider" type="xs:string"
codegen:nullValue="N" minOccurs="0"/>

<xs:element name="UserId" codegen:nullValue=" "
type="xs:string" minOccurs="0"/>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1"
msdata:primaryKey="true">
<xs:selector
xpath=".//mstns:MASped" />
<xs:field
xpath="mstns:StudentId" />
</xs:unique>
</xs:element>
 
K

Kevin Yu [MSFT]

Hi mklapp,

Sorry for keep you waiting for so long. I've checked it and found that it
is a known issue in ADO .net. When XmlSerializing the typed dataset, the
extended properties will not be persisted. So the nullValue attribute
cannot be passed through a web service.

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

mklapp

Bummer.
I hope that is scheduled for a fix someday.

regardless, thanks for closing the issue.

mklapp
 
M

mklapp

Hello,

I do want to thank you for resolving the question for
me. I know I have had posts here pertaining to this
issue for nearly a month. It is a relief to know what is
and what isn't.

However,

I read several articles addressing the codegen
namespace and its use. Not all were written by third
parties. Some were written by MS People.

In none of those article I recall reading, was there
any indication that this key technique was of absolutely
no use whatsoever in implementing your most
hyped 'platform configuration', XML Web Services.

Given the 'hot' nature of Web Services and the
inability of .NET to safely handle Null Values, I would
expect every single write up on the codegen namespace to
include a prominent disclaimer that this will not work
with Web Services. This is a piece of trivia that is
important to know for anyone who uses ADO.net, and yet no
one who read my original posts had any clue this
functionality was crippled for Web Services (a fact that
should not be obscure esoterica).

Regardless, I again thank you for closing this issue.

Michael Klapp
 

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