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

Xml string or Class definition

Hi,

When we define a web method, if the parameter is actually an xml, we can
either define the parameter as xml string like following:

public void webmethod(string xmldoc) { ... }

or we can create a class or set of classes that can be serialized to the
same xml like:

public void webmethod(class1 param) { ... }

what's the pros and cons of each way? what is the best practice? wsdl first
seems the way to go in .net 2.0 but for now what's the best way of doing
this?

Thanks!
John
Nov 23 '05 #1
1 2274
Hi John,

Welcome to MSDN newsgroup.
I think your question is a good one since I've also seen many others
discussing such problem over internet. As for pass/return xml data through
xml webservice, I think we should always avoid passing or return xml
directly trough string parameter or return value. This is becaues the
Webservice'S SOAP message itself is xml based , if we directdly inject
arbitrary xml data in SOAP message(pass xml as string parameter or return
value), the SOAP message is possible to be corrupted.

So I'd strongly recommend that we pass xml data through the .net's buildin
classes such as
XmlElement, XmlDocument like:
[WebMethod]
public XmlElement GetXmlElement()
{
XmlDocument doc = new XmlDocument();
XmlElement elm = doc.CreateElement("MyElement");
elm.InnerXml = "<elm><items><item id=\"1\">item1</item><item
id=\"2\">item1</item></items></elm>";

return elm;
}

In addition, for non- .NET client (when doing platform interop), we may
consider using our custom wrapper class which contains the xml data as
property and can be properly serizalized.

And here is a certain blog article which has mentioned this problem:

#Rant: Don't return XML in string variables!
http://blogs.msdn.com/mpowell/archiv...12/130637.aspx

HTH. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 23 '05 #2

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

Similar topics

8
by: Nick Keighley | last post by:
Hi, I want to store the representation of a class (called Thing in this post) in a string. The class provides no access to Thing's internal components but does provide an operator<<(). Defined...
7
by: Felix85 | last post by:
I am trying to make a command interpreter for a mud that i am working on the problem i am having right now is that i cannot convert the string into a char array. This is the error I am getting...
8
by: Jose Cintron | last post by:
Hello all. Newbie question here... I have a program that needs to do 1 of 2 things 1. declare a global System::String (which I think can't be done, because VS 2005 complains) 2. modify the...
3
by: usenet | last post by:
Kindly pardon my ignorance, but what is the way to declare a constant attribute of type string within a class? Thanks, Gus
9
by: jerry.upstatenyguy | last post by:
I am really stuck on this. I am trying to write a string array containing a "word" and a "definition" to a class called Entry. Ultimately this will end up in another class called dictionary. No,...
2
by: HerbD | last post by:
I have a loooong debugging session behind me! I finally found the reason for the problem and now would like to know, if it is a bug in my code or not standardconformant behavour of the compiler(s) or...
15
by: =?Utf-8?B?TWFkcyBOaWVsc2Vu?= | last post by:
Hi, I am developing a web service for a customer. The service has a method, that returns an array of Forms. Each form has a Name property of Type String. The customer wants the contract to...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
6
by: djm | last post by:
hello everyone, im doing a c++ coursework which consists linked lists and use of classes. but im getting some compilation errors. can some please help me out. //this is the header file...
7
by: Hendrik Schober | last post by:
Hi, this #include <string> class test { typedef std::string::size_type size_type; static const size_type x = std::string::npos; }; doesn't compile using either VC9 ("expected constant...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.