473,327 Members | 1,952 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,327 software developers and data experts.

Webmethod Accepting XmlDocument as argument, with WSDL reflecting

I've tried to search for an answer to this without much success, and I think
it's probably a common thing to do:
I have a web service I want to accept an XmlDocument as an argument which
conforms to a specific XSD that is defined. Right now when I declare
XmlDocument as my argument, it puts the old xml:any type in. How do I change
that to reflect the XSD that I'm looking for?

Thanks for any Help!
Nov 21 '05 #1
4 4611
Hi Matt,

There is no way to infer a specific document type when the input type is
XmlNode, XmlElement, etc. The reason is that these are the XML equivalent
of a generic object class. This is why in the WSDL you see that the
service is saying that it is capable of processing any type at all, which
is a very tall order indeed.

In order to get the WSDL to reflect the type you wish to support, you need
to use a type for inputs/return that is much more strongly typed. In your
case, you have a specific type in mind, so what you need to do is create a
.NET equivalent class that when serialized creates/consumes XML that
adheres to the rules you have defined in an XML schema.

In cases where you are starting from schema, you can use tools like XSD.exe
or XsdObjectGen (or some other similar tools) to create .NET classes that
mirror your schema intent. A caveat is that not everything that is
describable in XML schema is mappable to object based type systems, but if
you are careful to choose only the subset of base types that appear in XSD,
CLR and Java when you define your schema, you'll be well on your way using
one of these tools.

Once you create the assembly/classes that represent the schema defined
structures, you then use these via assembly reference or via direct
inclusion into your web service project (e.g. add reference, or add
source). Then you simply change your method signatures to use the strongly
typed classes instead of XML.

At runtime, this means your methods can be called as if they were being
passed the objects that you generated. This saves you a world of
programming headaches, since you don't have to interweve Xpath/XQuery code
into your business logic.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
Thread-Topic: Webmethod Accepting XmlDocument as argument, with WSDL
reflecting
thread-index: AcTZgM1GODL9hAWEQOu/8CjabQLoOA==
X-WBNR-Posting-Host: 68.157.154.79
From: "=?Utf-8?B?TWF0dEJlbGw=?=" <Ma******@discussions.microsoft.com>
Subject: Webmethod Accepting XmlDocument as argument, with WSDL reflecting
Date: Fri, 3 Dec 2004 13:41:09 -0800
Lines: 8
Message-ID: <05**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFT NGXA03.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7819
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

I've tried to search for an answer to this without much success, and I
think
it's probably a common thing to do:
I have a web service I want to accept an XmlDocument as an argument which
conforms to a specific XSD that is defined. Right now when I declare
XmlDocument as my argument, it puts the old xml:any type in. How do I
change
that to reflect the XSD that I'm looking for?

Thanks for any Help!

Nov 21 '05 #2
Dan Rogers wrote:
There is no way to infer a specific document type when the input type
is XmlNode, XmlElement, etc. The reason is that these are the XML
equivalent of a generic object class. This is why in the WSDL you see
that the service is saying that it is capable of processing any type
at all, which is a very tall order indeed.

In order to get the WSDL to reflect the type you wish to support, you
need to use a type for inputs/return that is much more strongly typed.
In your case, you have a specific type in mind, so what you need to do
is create a .NET equivalent class that when serialized
creates/consumes XML that adheres to the rules you have defined in an
XML schema.


... or write the WSDL by hand and continue on the path of pure XML. ;)

Remember, there's nothing that says your web service needs to actually generate
the WSDL. You can put your static WSDL file right up on the web server with
the ASMX and tell people to hit that URL instead of Foo.asmx?wsdl. It all
depends on how much time you want to spend getting your .NET model inline
with your XSD model or vice/versa. If the models are simple it's usually
not as big of an issue.

HTH,
Dre

Nov 23 '05 #3
I agree here completely. If the messages are really simple, it's six of
one or half dozen of the other. When the messages start to get complex
(think purchase order, employee data, etc), then I think it tilts to the
code-generation from schema side.

The hardest thing to do with raw XML, from my experience, is to create and
output XML that is schema compliant. This is why I recommend even for
simple structures to start with the schema, generate .NET classes, and use
those.

If you choose to post a static WSDL or use a generated one, this is
orthagonal, as long as what you post as a description corresponds with what
your service consumes and emits.

Dan
--------------------
Message-ID: <96*********************@msnews.microsoft.com>
From: Drew Marsh <dr****@hotmail.no.spamming.com>
Subject: RE: Webmethod Accepting XmlDocument as argument, with WSDL
reflecting
References: <tC**************@cpmsftngxa10.phx.gbl>
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-Newsreader: JetBrains Omea Reader 381.17
Newsgroups: microsoft.public.dotnet.framework.webservices
Date: Fri, 03 Dec 2004 15:37:07 -0800
NNTP-Posting-Host: 65.223.252.240
Lines: 1
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP14
.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7838
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Dan Rogers wrote:
There is no way to infer a specific document type when the input type
is XmlNode, XmlElement, etc. The reason is that these are the XML
equivalent of a generic object class. This is why in the WSDL you see
that the service is saying that it is capable of processing any type
at all, which is a very tall order indeed.

In order to get the WSDL to reflect the type you wish to support, you
need to use a type for inputs/return that is much more strongly typed.
In your case, you have a specific type in mind, so what you need to do
is create a .NET equivalent class that when serialized
creates/consumes XML that adheres to the rules you have defined in an
XML schema.


.. or write the WSDL by hand and continue on the path of pure XML. ;)

Remember, there's nothing that says your web service needs to actually
generate
the WSDL. You can put your static WSDL file right up on the web server with
the ASMX and tell people to hit that URL instead of Foo.asmx?wsdl. It all
depends on how much time you want to spend getting your .NET model inline
with your XSD model or vice/versa. If the models are simple it's usually
not as big of an issue.

HTH,
Drew
Nov 23 '05 #4
Just wanted to say thanks a whole bunch for these answers, they work like a
charm. My infopath form now automatically knows what columns I'm looking for
and will be returning!

"Dan Rogers" wrote:
I agree here completely. If the messages are really simple, it's six of
one or half dozen of the other. When the messages start to get complex
(think purchase order, employee data, etc), then I think it tilts to the
code-generation from schema side.

The hardest thing to do with raw XML, from my experience, is to create and
output XML that is schema compliant. This is why I recommend even for
simple structures to start with the schema, generate .NET classes, and use
those.

If you choose to post a static WSDL or use a generated one, this is
orthagonal, as long as what you post as a description corresponds with what
your service consumes and emits.

Dan
--------------------
Message-ID: <96*********************@msnews.microsoft.com>
From: Drew Marsh <dr****@hotmail.no.spamming.com>
Subject: RE: Webmethod Accepting XmlDocument as argument, with WSDL
reflecting
References: <tC**************@cpmsftngxa10.phx.gbl>
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-Newsreader: JetBrains Omea Reader 381.17
Newsgroups: microsoft.public.dotnet.framework.webservices
Date: Fri, 03 Dec 2004 15:37:07 -0800
NNTP-Posting-Host: 65.223.252.240
Lines: 1
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP14
.phx.gbl
Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.webservices:7838
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices

Dan Rogers wrote:
There is no way to infer a specific document type when the input type
is XmlNode, XmlElement, etc. The reason is that these are the XML
equivalent of a generic object class. This is why in the WSDL you see
that the service is saying that it is capable of processing any type
at all, which is a very tall order indeed.

In order to get the WSDL to reflect the type you wish to support, you
need to use a type for inputs/return that is much more strongly typed.
In your case, you have a specific type in mind, so what you need to do
is create a .NET equivalent class that when serialized
creates/consumes XML that adheres to the rules you have defined in an
XML schema.


.. or write the WSDL by hand and continue on the path of pure XML. ;)

Remember, there's nothing that says your web service needs to actually
generate
the WSDL. You can put your static WSDL file right up on the web server with
the ASMX and tell people to hit that URL instead of Foo.asmx?wsdl. It all
depends on how much time you want to spend getting your .NET model inline
with your XSD model or vice/versa. If the models are simple it's usually
not as big of an issue.

HTH,
Drew

Nov 23 '05 #5

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

Similar topics

3
by: Lars Moastuen | last post by:
I'm currently writing a webservice. I've successfully written a service that gives me some XML data, but now I want to link a XLS-stylesheet to that data. The way I'm trying to do that is to...
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
12
by: Whoever | last post by:
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); }
2
by: Danny Gagne | last post by:
I'm currently working an .net application (I can use 1.1 or 2.0 if needed) that needs to read a wsdl file and generate another piece of code that can use it. I'm encountering a problem where I...
2
by: svendtofte | last post by:
Hello, I've used wsdl.exe, to generate stub code for a WS at work. an example of the stub code is: ========================== /// <remarks/> public abstract class NavigatePublicationTarget :...
5
by: Ray Stevens | last post by:
I have a C# dataclass object that I would like to pass to a Web Service WebMethod, modify some strings, and return it to the caller but I am getting compiler errors in the client. I'm not an expert...
0
by: jjouett | last post by:
I'm defining a C# WebMethod where the argument has properties that are mandatory: public bool PerformTask(SimpleObject simpleObject) { .... } where SimpleObject is as follows:
8
by: Thirsty Traveler | last post by:
I have a WebMethod as follows: public XmlDocument OrderContract(XmlDocument doc) { return OrderBLL.OrderContract(doc); } However, the client is generating a compile error when the...
1
by: olrt | last post by:
Hello, I have designed a WebService with the following method : public DbAppAnswer GetDs(DbAppRequest request) DbAppRequest and DbAppAnswer are defined as :
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
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: 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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.