By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Webservice Dataset Type Fidelity Hoo Hah!!

P: n/a
Hello.

I am getting an InvalidCastException which has revealed yet more of my ignorance. I cant believe i
dont already know this and haven't encountered it before until now.

I am consuming a dataset from a webservice. I wrote both the server and client apps and the both use
the same middle teir. I fill a dataset on the server that has a relationship between two of the
tables inside. The relationship is between two strongly typed tables but is added dynamically as one
of the strongly typed tables is from another strongly typed dataset.

In consuming that from the client and then attempting to fill a datastore using the consumed dataset
i get the invalid cast exception when trying to traverse the relationship from child to parent row:

budgetRow =
CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPORT_SALESFIGURES & "_B"),
_ dsSalesBudget.SalesFiguresAggregateRow)

budgetRow is of type dsSalesBudget.SalesFiguresAggregateRow.

I couldn;t understand the exception because i believed i casting from a poly morphed
dsSalesBudget.SalesFiguresAggregateRow temporarily down cast to an untyped data row by the
GetParentRow method. But it turns out the row is not poly morphed at all but simply a datarow having
been stripped of its strong type i guess by the serialization process). Command line print our below
for interest.

Can anyone bring me up to speed here? Im a little embarrassed i got caught out by this because it
reeks of *basic learning* which clearly i haven;t got. Can anyone bring me up to speed here? I get
the same schema server side, before send, and after, once captured/consumed... which i would expect
but command line shows me the tables are clearly typed differently hence the invalid cast exception:

* server side *
? reports.tables(2)
{dsSalesBudget.SalesFiguresAggregateDataTable}
[dsSalesBudget.SalesFiguresAggregateDataTable]: {dsSalesBudget.SalesFiguresAggregateDataTable}

* client side *
? reports.tables(2)
{System.Data.DataTable}
CaseSensitive: False
ChildRelations: {System.Data.DataRelationCollection.DataTableRelat ionCollection}

Thanks
Richard
Nov 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Richard,

Do not tell so much at the start of your message, the error is as I assume
form your message in this,
budgetRow =
CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPORT_SALESFIGURES
& "_B"),
_ dsSalesBudget.SalesFiguresAggregateRow)


That is enough to show your problem in my opinion, going on in this you can
than explain more.

This statement is abolutly not possible. (It is impossible because of that
string connection).

I will try to tell you something about casting and converting from a
dataset.

A dataset is a tree of objects, a strongly typed dataset is to help you to
easily go trough that tree and that without that casting is needed, so
normally it should not be needed.

However trying to explain it more in a simple way, an object is nothing
more than a box that holds values or again other objects.

By instance,
dim a as object = 1
This will create an object with an integer with the value 1 in it.

Dim b As Integer = DirectCast(a, Integer)
Get that 1 out of that box (object) as an integer (there are a lot more
posibilities to do that by instance just CInt what is in fact a convert
function, however more easy to write, and probably therefore mostly used)

Dim c As Double = CDbl(a)
Converts an integer to a double

Dim d As String = CType(a, String)
Gets the integer from the object and converts it to a string (object)

Dim e As String = a.ToString
Does the same as above and is mostly used for that instead of the one above.
It is only for strings on every object.

Because of the fact, that the way you can write the casting and converting,
is very much dependend from the used program language, I advice you to ask
this kind of questions the next time in the newsgroup.

microsoft.public.dotnet.languages.vb

I hope this helps something?

Cor

Nov 22 '05 #2

P: n/a
JD
What does you web method signature look like?
"Richard Myers" <fa**@address.com> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Hello.

I am getting an InvalidCastException which has revealed yet more of my ignorance. I cant believe i dont already know this and haven't encountered it before until now.

I am consuming a dataset from a webservice. I wrote both the server and client apps and the both use the same middle teir. I fill a dataset on the server that has a relationship between two of the tables inside. The relationship is between two strongly typed tables but is added dynamically as one of the strongly typed tables is from another strongly typed dataset.

In consuming that from the client and then attempting to fill a datastore using the consumed dataset i get the invalid cast exception when trying to traverse the relationship from child to parent row:
budgetRow =
CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPOR
T_SALESFIGURES & "_B"), _ dsSalesBudget.SalesFiguresAggregateRow)

budgetRow is of type dsSalesBudget.SalesFiguresAggregateRow.

I couldn;t understand the exception because i believed i casting from a poly morphed dsSalesBudget.SalesFiguresAggregateRow temporarily down cast to an untyped data row by the GetParentRow method. But it turns out the row is not poly morphed at all but simply a datarow having been stripped of its strong type i guess by the serialization process). Command line print our below for interest.

Can anyone bring me up to speed here? Im a little embarrassed i got caught out by this because it reeks of *basic learning* which clearly i haven;t got. Can anyone bring me up to speed here? I get the same schema server side, before send, and after, once captured/consumed... which i would expect but command line shows me the tables are clearly typed differently hence the invalid cast exception:
* server side *
? reports.tables(2)
{dsSalesBudget.SalesFiguresAggregateDataTable}
[dsSalesBudget.SalesFiguresAggregateDataTable]: {dsSalesBudget.SalesFiguresAggregateDataTable}
* client side *
? reports.tables(2)
{System.Data.DataTable}
CaseSensitive: False
ChildRelations: {System.Data.DataRelationCollection.DataTableRelat ionCollection}
Thanks
Richard

Nov 22 '05 #3

P: n/a
Hi Cor

I have no idea what your dribbling on about?

Do not tell so much at the start of your message, the error is as I assume
form your message in this,
I'll phrase and word my messages however i see fit.
budgetRow =
CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPORT_SALESFIGURES
& "_B"),
_ dsSalesBudget.SalesFiguresAggregateRow)
That is enough to show your problem in my opinion, going on in this you can
than explain more.

This statement is abolutly not possible. (It is impossible because of that
string connection).


It is absolutely possible. I do it several times in the remainder of the application.
SalesManagementBase.RELATION_SALESAGENTPERIODREPOR T_SALESFIGURES & "_B" is simply a string which when used in this way converts to the name of a relation. Check out the method signature for GetParentRow before you make your decisions about what is and what is
not possible?
I will try to tell you something about casting and converting from a
dataset.

A dataset is a tree of objects, a strongly typed dataset is to help you to
easily go trough that tree and that without that casting is needed, so
normally it should not be needed.

However trying to explain it more in a simple way, an object is nothing
more than a box that holds values or again other objects.

By instance,
dim a as object = 1
This will create an object with an integer with the value 1 in it.

Dim b As Integer = DirectCast(a, Integer)
Get that 1 out of that box (object) as an integer (there are a lot more
posibilities to do that by instance just CInt what is in fact a convert
function, however more easy to write, and probably therefore mostly used)

Dim c As Double = CDbl(a)
Converts an integer to a double

Dim d As String = CType(a, String)
Gets the integer from the object and converts it to a string (object)

Dim e As String = a.ToString
Does the same as above and is mostly used for that instead of the one above.
It is only for strings on every object.

What has this got to do with my question? Im not looking for a 101 primer on object types. Im asking
about type fidelity over the wire?

Because of the fact, that the way you can write the casting and converting,
is very much dependend from the used program language, I advice you to ask
this kind of questions the next time in the newsgroup.

microsoft.public.dotnet.languages.vb
I'll decide which newsgroup best suits my purpose. The question i am asking could well go into
ADO.net/webservices/c#/vb.net. So in this case i chose general.

I hope this helps something?

Cor


No it didn't. It was irritating at best.

Richard
Nov 22 '05 #4

P: n/a
Richard,

Sorry because your huge amount of text I missed the "report.getparentrow".

In a news message it is not so easy reading and therefore I assumed you
where missing what is casting.

So forget it.

Telling that it was irritating, was however very overdone.

I am glad you cannot make mistakes and will keep that in mind with your next
message, knowing that you need no help because of that.

Cor

"Richard Myers" <fa**@address.com>
...
Hi Cor

I have no idea what your dribbling on about?

Do not tell so much at the start of your message, the error is as I
assume
form your message in this,


I'll phrase and word my messages however i see fit.
budgetRow =
CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPORT_SALESFIGURES
& "_B"),
> _ dsSalesBudget.SalesFiguresAggregateRow)


That is enough to show your problem in my opinion, going on in this you
can
than explain more.

This statement is abolutly not possible. (It is impossible because of
that
string connection).


It is absolutely possible. I do it several times in the remainder of the
application.
SalesManagementBase.RELATION_SALESAGENTPERIODREPOR T_SALESFIGURES
& "_B" is simply a string which when used in this way converts to the
name of a relation. Check

out the method signature for GetParentRow before you make your decisions
about what is and what is
not possible?
I will try to tell you something about casting and converting from a
dataset.

A dataset is a tree of objects, a strongly typed dataset is to help you
to
easily go trough that tree and that without that casting is needed, so
normally it should not be needed.

However trying to explain it more in a simple way, an object is nothing
more than a box that holds values or again other objects.

By instance,
dim a as object = 1
This will create an object with an integer with the value 1 in it.

Dim b As Integer = DirectCast(a, Integer)
Get that 1 out of that box (object) as an integer (there are a lot more
posibilities to do that by instance just CInt what is in fact a convert
function, however more easy to write, and probably therefore mostly used)

Dim c As Double = CDbl(a)
Converts an integer to a double

Dim d As String = CType(a, String)
Gets the integer from the object and converts it to a string (object)

Dim e As String = a.ToString
Does the same as above and is mostly used for that instead of the one
above.
It is only for strings on every object.

What has this got to do with my question? Im not looking for a 101 primer
on object types. Im asking
about type fidelity over the wire?

Because of the fact, that the way you can write the casting and
converting,
is very much dependend from the used program language, I advice you to
ask
this kind of questions the next time in the newsgroup.

microsoft.public.dotnet.languages.vb


I'll decide which newsgroup best suits my purpose. The question i am
asking could well go into
ADO.net/webservices/c#/vb.net. So in this case i chose general.

I hope this helps something?

Cor


No it didn't. It was irritating at best.

Richard

Nov 22 '05 #5

P: n/a
JD
When you expose the typed dataset returned by the web service call, does the
typed dataset describe both typed tables and the relationship between them?
Or does the typed dataset describe only the one original typed table?

What I'm getting at is, does the WSDL thats created on the client describe
this relationship? The Visual Studio auto-generated WSDL is created from the
type exposed by your web service method. If your type does not describe the
second table type and the relationship, then the WSDL won't either, and
thats probably why you are losing type information.

Take a look at your client's web reference (make sure show all files is on).
Does the WSDL and the XSD describe the type and relationship thats missing?

JD
"Richard Myers" <fa**@address.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
Hi JD

<WebMethod()> _
Public Function GetNonReviewedSalesAgentPeriodReports(ByVal credential As NetworkCredential) As dsSalesAgentPeriodReport

dsSalesAgentPeriodReport is the dataset into which another strongly typed table of type dsSalesBudget.SalesFiguresAggregate is merged.

The type of this table remains as dsSalesBudget.SalesFiguresAggregate even when merged into dsSalesAgentPeriodReport as i would expect but once consumed by the webservice it is downcast to System.Data.DataTable?

Thanks
Richard

"JD" <no@spam.com> wrote in message

news:M01od.545384$mD.510187@attbi_s02...
What does you web method signature look like?
"Richard Myers" <fa**@address.com> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
Hello.

I am getting an InvalidCastException which has revealed yet more of my

ignorance. I cant believe i
dont already know this and haven't encountered it before until now.

I am consuming a dataset from a webservice. I wrote both the server
and client apps and the both use
the same middle teir. I fill a dataset on the server that has a

relationship between two of the
tables inside. The relationship is between two strongly typed tables
but is added dynamically as one
of the strongly typed tables is from another strongly typed dataset.

In consuming that from the client and then attempting to fill a
datastore using the consumed dataset
i get the invalid cast exception when trying to traverse the
relationship from child to parent row:

budgetRow =

CType(report.GetParentRow(SalesManagementBase.RELA TION_SALESAGENTPERIODREPOR T_SALESFIGURES & "_B"),
_ dsSalesBudget.SalesFiguresAggregateRow)

budgetRow is of type dsSalesBudget.SalesFiguresAggregateRow.

I couldn;t understand the exception because i believed i casting from
a poly morphed
dsSalesBudget.SalesFiguresAggregateRow temporarily down cast to an
untyped data row by the
GetParentRow method. But it turns out the row is not poly morphed at
all but simply a datarow having
been stripped of its strong type i guess by the serialization
process). Command line print our below
for interest.

Can anyone bring me up to speed here? Im a little embarrassed i got
caught out by this because it
reeks of *basic learning* which clearly i haven;t got. Can anyone
bring me up to speed here? I get
the same schema server side, before send, and after, once

captured/consumed... which i would expect
but command line shows me the tables are clearly typed differently
hence the invalid cast exception:

* server side *
? reports.tables(2)
{dsSalesBudget.SalesFiguresAggregateDataTable}
[dsSalesBudget.SalesFiguresAggregateDataTable]:

{dsSalesBudget.SalesFiguresAggregateDataTable}

* client side *
? reports.tables(2)
{System.Data.DataTable}
CaseSensitive: False
ChildRelations:

{System.Data.DataRelationCollection.DataTableRelat ionCollection}

Thanks
Richard



Nov 22 '05 #6

P: n/a

Sorry because your huge amount of text I missed the "report.getparentrow".

In a news message it is not so easy reading and therefore I assumed you
where missing what is casting.

So forget it.

Telling that it was irritating, was however very overdone.

I am glad you cannot make mistakes and will keep that in mind with your next
message, knowing that you need no help because of that.


Hi Cor,

I have made many mistakes and will probably continue to make some more. That is generally the best
way to learn. My irritation was not at your off beat response to my question, i have done that
myself several times such is the nature of newsgroup postings. It was instead directed towards your
telling me "what" too write. You often seem to take it upon yourself to tell posters where to post
and when to post.... and now when you wanted to tell me "how and what" to post, I felt was very over
done and as i say "irritating" especially given your misdirected response.

If you had of read the "huge" amount of text you told me not to include which i considered the
"context" of the message, you would have known that i had already identitifed the error as being
that of casting ( i even included a command line dump), and that i understood why this had occured.
My message was subject "webservice dataset type fidelity" not "Casting Error - I dont understand?".
I also fail to see how you missed report.getparentrow when you cut and pasted that section of code
and then told me that is all my message should have been?

Either way i have worked around the error now and have moved on.

In hindsight, i suppose my response was a little caustic, but thats what im like when irritated.
(And i suppose the obvious joke is that, in that case i seem to be irratated all the time.) For that
i apologise.

Richard

Nov 22 '05 #7

P: n/a
Hi JD

You're absolutely right. Im a complete idiot!

I was thinking about the schema of the dataset once it had arrived on the client in terms of how i
was using it rather than the schema of the service definition.

What is worse is that i have clearly taken a very insular, and somewhat lazy approach to the
architecture of the service by exposing a service that is not adequately defined by it's WSDL/
webmethod signatures. It requires implicit knowlegde of the service which is like the "complete
opposite" of what a webservice should be.
Its only an internal/small project service so i figured I'd take a shortcut and then promptly forgot
that even i had taken it.

Quite shocking really.

Good job i sometimes quite like having my backside paddled..... by the right kind of woman of
course..... as i think i should really be pulling my britches down for this one!

Thanks again!

Richard


Nov 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.