views:

48

answers:

3

Camarades,

I am developing a WebService, and wish to make it accessible to everyone, in all languages in a simple and practical way. For one of the access, I need to send two pieces of information, a token and an XML.

In this case, was in doubt, I use parameters: String - String or String - XmlDocument?

Well, in other words, my question is, it is advisable to use String parameters are XML documents? What is the experience of you in this?

+1  A: 

If you are going to be sending XML to a web service, then you should probably expose it as an XmlDocument, just to make sure folks looking at the service definition understand what needs to be passed in.

That being said, with traditional SOAP services it is generally considered bad to take XML blobs as arguments, because they are not self-describing, and versioning becomes a nightmare (you need to support all versions of the XmlDocument your service has ever been able to use...so if you change it twice a year, in 3 years you'll have 6 different XML document formats you need to be able to support).

ckramer
@ckramer in a C # application, it would be advisable to use XmlDocument or XmlElement? I will perform some tests, thanks for sharing your experience, and response.
Ph.E
@Ph: You'd just as well use XmlElement. When you use XmlDocument, XmlElement is used instead. When you think about it, it doesn't make sense to have an XML document nested inside another XML document.
John Saunders
@John Saunders Yes, I was reading about the relationship of classes. I thought of this, why I created a web method with XmlDocument parameter, and when I use it (reference) parameter was XmlElement. Thanks.
Ph.E
A: 

i've always used string paramaters. I think, but i'm not sure, that a serialized xmldocument is larger than the xml data itself. Besides that, i don't think a PHP application can call a webservices which needs an XmlDocument.

Michel
@Michel: -1: if you're not sure about something, then I suggest you keep it to yourself until you are sure. In this case, you're just flat wrong.
John Saunders
+1  A: 

If you want your service to be usable by any client, then passing an XmlElement is not the way to go. This puts no information into the WSDL that the client can use to decide what to send you.

Instead, pass a simple "Data Transfer Object" class. This will be a simple class with no behavior, only data. For instance:

public class PersonDTO
{
    public int ID {get;set;}
    public string Name {get;set;}
    public List<AddressDTO> Addresses {get;set;}
}

public class AddressDTO
{
    public string Line1 {get;set;}
    public string City {get;set;}
    public string PostalCode {get;set;}
}

Have your webmethod accept one of these as a parameter, and it will be usable by almost every client in the world.

John Saunders
@John Saunders But my data are in a struct, and this struct is not being imported from the web service. On the client, it creates a new object that ArraOfT [StructObject]. Therefore, many controls do need to modify and process information. So I'm thinking of serializing objects at both ends. That would solve my problem. So I'm thinking of serializing the object, send as a string or XmlDocument, gets it and then serialize an object again.
Ph.E
@Ph: your structs or other types are _never_ "imported" from the web service. It just doesn't work that way. See [How Web Services Work](http://johnwsaundersiii.spaces.live.com/blog/cns!600A2BE4A82EA0A6!523.entry) to learn why your struct will never arrive at the client.
John Saunders