Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2005

Tip: Looking for answers? Try searching our database.

Xml string or Class definition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Lee - 30 Mar 2005 07:54 GMT
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
Steven Cheng[MSFT] - 30 Mar 2005 09:44 GMT
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/archive/2004/05/12/130637.aspx

HTH. Thanks,

Steven Cheng
Microsoft Online Support

Signature

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


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.