468,783 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

How to add schema information into xmldocument from typed dataset

Hi,

I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}

In WSDL, it shows returned type as xml; in the result, it shows the xml
data.

How do I put schema information in both places?

Thanks.
Nov 21 '05 #1
12 5080
You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}

In WSDL, it shows returned type as xml; in the result, it shows the xml
data.

How do I put schema information in both places?

Thanks.

Nov 21 '05 #2
Thanks for the reply. I'm not try to read, but to write. I already have
data in the dataset and trying to return it from a web service as
xmldocument of course.

Just saw there's a ds.WriteXml(????, XmlWriteMode.WriteSchema)

But all examples I can find are trying to write to a file. I need to write
into an XmlNode/XmlDocument/XmlDataDocument and return it.

Of course, it's better to have the schema information in WSDL as well.

Any ideas?
"Scott M." <s-***@nospam.nospam> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}

In WSDL, it shows returned type as xml; in the result, it shows the xml
data.

How do I put schema information in both places?

Thanks.


Nov 21 '05 #3
The WriteXml method on the DataSet allows you to write to a string or to a
stream.
http://msdn.microsoft.com/library/en...teXmlTopic.asp

You do not need to write to a file.

You can also call GetXmlSchema method on the dataset, and put that into a
string.
http://msdn.microsoft.com/library/en...chematopic.asp

Consider using 2 methods - one that returns the schema and one that returns
the data. Either that or put them into different XmlDocuments.

-Dino

"Whoever" <bz****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks for the reply. I'm not try to read, but to write. I already have
data in the dataset and trying to return it from a web service as
xmldocument of course.

Just saw there's a ds.WriteXml(????, XmlWriteMode.WriteSchema)

But all examples I can find are trying to write to a file. I need to
write
into an XmlNode/XmlDocument/XmlDataDocument and return it.

Of course, it's better to have the schema information in WSDL as well.

Any ideas?
"Scott M." <s-***@nospam.nospam> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I'm trying to return an XmlDocument or XmlNode converted from a typed
> dataset.
>
> public XmlNode whatever() {
> MyTypedDataSet ds = new MyTypedDataSet();
> return new XmlDataDocument(ds);
> }
>
> In WSDL, it shows returned type as xml; in the result, it shows the xml
> data.
>
> How do I put schema information in both places?
>
> Thanks.
>
>



Nov 21 '05 #4
I would use the GetXML and GetXMLSchema methods that return their respective
data as strings.

"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:e7**************@TK2MSFTNGP14.phx.gbl...
The WriteXml method on the DataSet allows you to write to a string or to
a stream.
http://msdn.microsoft.com/library/en...teXmlTopic.asp

You do not need to write to a file.

You can also call GetXmlSchema method on the dataset, and put that into a
string.
http://msdn.microsoft.com/library/en...chematopic.asp

Consider using 2 methods - one that returns the schema and one that
returns the data. Either that or put them into different XmlDocuments.

-Dino

"Whoever" <bz****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks for the reply. I'm not try to read, but to write. I already have
data in the dataset and trying to return it from a web service as
xmldocument of course.

Just saw there's a ds.WriteXml(????, XmlWriteMode.WriteSchema)

But all examples I can find are trying to write to a file. I need to
write
into an XmlNode/XmlDocument/XmlDataDocument and return it.

Of course, it's better to have the schema information in WSDL as well.

Any ideas?
"Scott M." <s-***@nospam.nospam> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I'm trying to return an XmlDocument or XmlNode converted from a typed
> dataset.
>
> public XmlNode whatever() {
> MyTypedDataSet ds = new MyTypedDataSet();
> return new XmlDataDocument(ds);
> }
>
> In WSDL, it shows returned type as xml; in the result, it shows the
> xml
> data.
>
> How do I put schema information in both places?
>
> Thanks.
>
>



Nov 21 '05 #5
Thanks again for your follow up.

When returning a string, how can I add the schema information to WSDL so
that the service client have access to the data structure at design time?
"Scott M." <s-***@nospam.nospam> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
I would use the GetXML and GetXMLSchema methods that return their respective data as strings.

"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:e7**************@TK2MSFTNGP14.phx.gbl...
The WriteXml method on the DataSet allows you to write to a string or to a stream.
http://msdn.microsoft.com/library/en...teXmlTopic.asp
You do not need to write to a file.

You can also call GetXmlSchema method on the dataset, and put that into a string.
http://msdn.microsoft.com/library/en...chematopic.asp
Consider using 2 methods - one that returns the schema and one that
returns the data. Either that or put them into different XmlDocuments.

-Dino

"Whoever" <bz****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thanks for the reply. I'm not try to read, but to write. I already have data in the dataset and trying to return it from a web service as
xmldocument of course.

Just saw there's a ds.WriteXml(????, XmlWriteMode.WriteSchema)

But all examples I can find are trying to write to a file. I need to
write
into an XmlNode/XmlDocument/XmlDataDocument and return it.

Of course, it's better to have the schema information in WSDL as well.

Any ideas?
"Scott M." <s-***@nospam.nospam> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
You don't have to have all the XML in one XML document.

You can first load up the DataSet with the schema:
dataset.ReadXMLSchema(xmlSchemaNode)
and then read in the data from a different node:
dataset.ReadXML(xmlDataNode)

Be sure to read the schema in first though.
"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I'm trying to return an XmlDocument or XmlNode converted from a typed > dataset.
>
> public XmlNode whatever() {
> MyTypedDataSet ds = new MyTypedDataSet();
> return new XmlDataDocument(ds);
> }
>
> In WSDL, it shows returned type as xml; in the result, it shows the
> xml
> data.
>
> How do I put schema information in both places?
>
> Thanks.
>
>



Nov 21 '05 #6
Whoever wrote:
When returning a string, how can I add the schema information to WSDL
so that the service client have access to the data structure at design
time?


You can't. That's the point I was trying to make in the thread in this newsgroup titled "Passing a Dataset to a webservice"[1] which unfortunately ended up getting ugly. I'd hate to have to try and explain it again, but it sounds like you already understand the difference.

HTH,
Drew

[1] http://groups.google.com/groups?hl=e...TNGP09.phx.gbl
Nov 21 '05 #7
Whoever wrote:
I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}
In WSDL, it shows returned type as xml; in the result, it shows the
xml data.

How do I put schema information in both places?


If I'm correct in assuming that "whatever()" is your web method, then all you need to to is return MyTypedDataSet instead of XmlNode. By returning Xml node, the WSDL generator has no clue what the content of that node might be, so all it can do is put <xsd:any /> as the signature of your web method's message. If you change it to return MyTypedDataSet instead, it will understand that you want to return a more specific type and instead it will be more specifc and put <xsd:any namespace="<the uri of your typed dataset here>" />.

Now when someone generates a web reference (proxy) they'll also get your typed data set on the client side as well instead of just having to deal with a string.

HTH,
Drew
Nov 21 '05 #8
I started with return MyTypedDataSet directly, but don't like <xsd:any /> in
the WSDL. You mean I can manually edit the WSDL and add <xsd:any
namespace="url of typed dataset" /> ?

Is this solution fully compatiable with all sorts clients, like Java based
solution? For example, will a Coldfusion client be able to fully,
automacitally understand the service?

Most of my applications are .NET based, so I can just throw dataset around
without even thinking, but this one is an exception. I want it to be a
well-formed, fully compatible, professional looking service.

I also tried using custom collection, it has a nice looking WSDL, but I
couldn't fingure out a way to auto generate a schema and send it back with
the data.

Any solutions? Really appreciate your help.

"Drew Marsh" <dr****@hotmail.no.spamming.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Whoever wrote:
I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}
In WSDL, it shows returned type as xml; in the result, it shows the
xml data.

How do I put schema information in both places?
If I'm correct in assuming that "whatever()" is your web method, then all

you need to to is return MyTypedDataSet instead of XmlNode. By returning Xml
node, the WSDL generator has no clue what the content of that node might be,
so all it can do is put <xsd:any /> as the signature of your web method's
message. If you change it to return MyTypedDataSet instead, it will
understand that you want to return a more specific type and instead it will
be more specifc and put <xsd:any namespace="<the uri of your typed dataset
here>" />.
Now when someone generates a web reference (proxy) they'll also get your typed data set on the client side as well instead of just having to deal
with a string.
HTH,
Drew

Nov 21 '05 #9
BTW, forgot the reason why I turned to xmldocument instead of dataset.

When returning dataset, it has lots of additional information like diffgram
etc. Some of the consumer of this service acutally manually coded
everything, so they tend to complain about anything that's not 100%
necessary and complaince with standard.
"Whoever" <bz****@hotmail.com> wrote in message
news:e7**************@TK2MSFTNGP09.phx.gbl...
I started with return MyTypedDataSet directly, but don't like <xsd:any /> in the WSDL. You mean I can manually edit the WSDL and add <xsd:any
namespace="url of typed dataset" /> ?

Is this solution fully compatiable with all sorts clients, like Java based
solution? For example, will a Coldfusion client be able to fully,
automacitally understand the service?

Most of my applications are .NET based, so I can just throw dataset around
without even thinking, but this one is an exception. I want it to be a
well-formed, fully compatible, professional looking service.

I also tried using custom collection, it has a nice looking WSDL, but I
couldn't fingure out a way to auto generate a schema and send it back with
the data.

Any solutions? Really appreciate your help.

"Drew Marsh" <dr****@hotmail.no.spamming.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Whoever wrote:
I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}
In WSDL, it shows returned type as xml; in the result, it shows the
xml data.

How do I put schema information in both places?
If I'm correct in assuming that "whatever()" is your web method, then

all you need to to is return MyTypedDataSet instead of XmlNode. By returning Xml node, the WSDL generator has no clue what the content of that node might be, so all it can do is put <xsd:any /> as the signature of your web method's
message. If you change it to return MyTypedDataSet instead, it will
understand that you want to return a more specific type and instead it will be more specifc and put <xsd:any namespace="<the uri of your typed dataset
here>" />.

Now when someone generates a web reference (proxy) they'll also get your

typed data set on the client side as well instead of just having to deal
with a string.

HTH,
Drew


Nov 21 '05 #10
I'm gonna address both your posts in one shot here as not to clutter up the thread:
I started with return MyTypedDataSet directly, but don't like
<xsd:any /> in the WSDL.
I don't blame you... it's like the XML equivalent of VARIANT. ;)
You mean I can manually edit
the WSDL and add <xsd:any namespace="url of typed dataset" /> ?
No, you shouldn't have to edit the WSDL at all. Look at the WSDL it's generating for you now. Do you see a wsdl:import as the very child element of wsdl:definitions? It should look something like this:

<wsdl:import
namespace="<your namespace URI here>"
location="http://<your server>/Service.asmx?schema=<your typed dataset type name here>" />

If not then something's not right because I'm testing the scenario of a typed DataSet here for you to make sure I'm giving the right answers and mine's typing it correctly.
BTW, forgot the reason why I turned to xmldocument instead of dataset.

When returning dataset, it has lots of additional information like
diffgram etc. Some of the consumer of this service acutally manually
coded everything, so they tend to complain about anything that's not
100% necessary and complaince with standard.


Yes, I agree... the diffgram and schema just don't belong as part of the message. This is why I don't like the way DataSet serializes itself at all by default and why I generally recommend that people avoid using it as a type in their web methods signatures altogether if they're expecting the data to be sent/received correctly.

Anyway, if you got with XmlDataDocument and returning XmlDocument that's fine, but now you start running into the limitations of the automagic WSDL generator. By returning XmlDocument the best the WSDL generator can do is assume xsd:any, so we're back to square one if we don't do some more work. This article[1] documents the pitfalls of DataSets and some hacks to get the correct WSDL generated. The one you'd need to resort to specifically is where you create a "stand-in" .NET type that helps generate the correct schema by decorating the type itself with XML serialization attributes.

In closing, life becomes a *lot* easier if you just create the WSDL document yourself and host it as a static document on the web server if you'd like people to be able to generate web references based off it. You wouldn't even need a typed Dataset at that point, you can just use a plain vanilla DataSet. This is why the WSDL First![2] movement was undertaken in the first place. If you don't think in terms of XML Schema and WSDL and just rely on the tools to generate things for you there's no way you're going to get the strong typing at the XML level that you *really* should be striving for. WebServices are so young and so in flux, the toolsets/frameworks of today have a hard time doing the "right thing" for you.

HTH,
Drew

[1] http://msdn.microsoft.com/library/de...ce02112003.asp
[2] http://www.google.com/search?q=WSDL+first
Nov 21 '05 #11
Just picked up a message I posted a few days ago where Dan Rogers points
out some confusion I had all these time.

Basically DataSet has type any in WSDL and schema as part of the return data
at run time. The truth is schema information should be in WSDL to
facilitate design time reference. I have already done that through custom
collection, but still kind of stucked with the idea of making schema part of
the return data, which is mostly uneccessary (Excel web query still
complains it has no schema, but I think I'll pass that one).

So seems fine tuning the custom collection with XmlAttribute is a more
practical approach.

Thanks for everyone's help. Really appreicate it.

BTW, if anyone has a good example of using typed dataset and still be able
to have a perfect WSDL, I wouldn't mind rewrite all my codes. Somehow Typed
DataSet always sounds better.

"Whoever" <bz****@hotmail.com> wrote in message
news:ew*************@TK2MSFTNGP11.phx.gbl...
Hi,

I'm trying to return an XmlDocument or XmlNode converted from a typed
dataset.

public XmlNode whatever() {
MyTypedDataSet ds = new MyTypedDataSet();
return new XmlDataDocument(ds);
}

In WSDL, it shows returned type as xml; in the result, it shows the xml
data.

How do I put schema information in both places?

Thanks.

Nov 21 '05 #12
> Basically DataSet has type any in WSDL and schema as part of the
return data at run time.
Anytime you use DataSet in the signature of your .NET method you're going to get bitten because: a) the WSDL generator can't provide the strong typing you want and b) DataSet is going to use it's schema/diffgram serialization approach.
The truth is schema information should be in
WSDL to facilitate design time reference.
Yeah, schema in the WSDL is the only way for clients to *really* know what XML types expect. The inline schema is basically the same as defining a method as taking a VARIANT in COM.
BTW, if anyone has a good example of using typed dataset and still be
able to have a perfect WSDL, I wouldn't mind rewrite all my codes.
Somehow Typed DataSet always sounds better.


To the best of my knowledge this is just never gonna work because you're still gonna end up passing the schema/diffgram. :S

Anyway, glad to hear you got a solution that works.

Happy coding,
Drew
Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Scott M. | last post: by
2 posts views Thread by Frosty | last post: by
3 posts views Thread by MR | last post: by
1 post views Thread by Martin | last post: by
4 posts views Thread by =?Utf-8?B?Sm9iIExvdA==?= | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.