开发者

Patterns/Best Practices Parameters WebService

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 informa开发者_StackOverflow社区tion, 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?


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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜