473,654 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4642
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: AcTZgM1GODL9hAW EQOu/8CjabQLoOA==
X-WBNR-Posting-Host: 68.157.154.79
From: "=?Utf-8?B?TWF0dEJlbGw =?=" <Ma******@discu ssions.microsof t.com>
Subject: Webmethod Accepting XmlDocument as argument, with WSDL reflecting
Date: Fri, 3 Dec 2004 13:41:09 -0800
Lines: 8
Message-ID: <05************ *************** *******@microso ft.com>
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.publi c.dotnet.framew ork.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.1.29
Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA01.phx.gbl!TK 2MSFTNGXA03.phx .gbl
Xref: cpmsftngxa10.ph x.gbl
microsoft.publi c.dotnet.framew ork.webservices :7819
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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************ *********@msnew s.microsoft.com >
From: Drew Marsh <dr****@hotmail .no.spamming.co m>
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.publi c.dotnet.framew ork.webservices
Date: Fri, 03 Dec 2004 15:37:07 -0800
NNTP-Posting-Host: 65.223.252.240
Lines: 1
Path:
cpmsftngxa10.ph x.gbl!TK2MSFTNG XA03.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP1 4
.phx.gbl
Xref: cpmsftngxa10.ph x.gbl
microsoft.publi c.dotnet.framew ork.webservices :7838
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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************ *********@msnew s.microsoft.com >
From: Drew Marsh <dr****@hotmail .no.spamming.co m>
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.publi c.dotnet.framew ork.webservices
Date: Fri, 03 Dec 2004 15:37:07 -0800
NNTP-Posting-Host: 65.223.252.240
Lines: 1
Path:
cpmsftngxa10.ph x.gbl!TK2MSFTNG XA03.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP1 4
.phx.gbl
Xref: cpmsftngxa10.ph x.gbl
microsoft.publi c.dotnet.framew ork.webservices :7838
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
420
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 create a webmethod that returns a XmlDataDocument, and use CreateProcessingInstruction() to add a "stylesheet-header"... Problem is that the headers I add using CreateProcessingInstruction() seems to be removed (?) when the data is transferred over the...
7
4892
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: Value of type System.xml.xmldocument cannot be converted to System.IO.textreader. I would think this is possible to do. Code snippet is below:
12
5298
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
7727
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 cannot extract all of the type information from the wsdl using any standard tools. I'm using HttpGet style webservices if that makes any difference, but I want to be able to use any type. 1. I've tried the ServiceDescription.Types and I cannot...
2
3483
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 : System.Web.Services.WebService {
5
3449
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 on Web Services and am wondering if what I am attempting is even doable? Even this simple test generates the error: From the Web Service:
0
1676
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
2823
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 following lines are used:
1
1817
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
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.