473,372 Members | 1,236 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,372 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 4614
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.