Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Service: Single String Parameter Or Complex Type Parameters

Is it more or less acceptable (i.e. standard) to create a publicly-exposed web service with these method signatures:

ThisMethodDoesSomething(ComplexType param)

ThisMethodDoesSomethingElse(AnotherComplexType param)

Or this:

ThisMethodDoesSomethingAndSomethingElse(string xml)

Where the operation being performed depends upon the XML string passed to a single does-it-all method? I have always gone with the former, but a coworker of mine prefers the latter and I'm trying to weigh pros and cons of both strategies before we begin a new project. Which is more accepted and easier for the public to work with and why?

like image 836
Brad Wesley Avatar asked Aug 16 '10 15:08

Brad Wesley


People also ask

What is string parameter?

It means you can pass an arbitrary number of arguments to the method (even zero). In the method, the arguments will automatically be put in an array of the specified type, that you use to access the individual arguments.


2 Answers

I would never send an XML string. First of all, "XML" is not the same thing as "string". They do not follow the same rules.

Any reasonable client can accept a complex type consisting of primitive types and lists or arrays of primitive types, recursively (C# syntax):

public class ComplexType1
{
    public int IntegerProperty {get;set;}
    public int[] ArrayOfIntegers {get;set;}
    public List<int> ListOfIntegers {get;set;} // Same as ArrayOfIntegers
}

public class ComplexType2
{
    public ComplexType1 CT1 {get;set;}
    public List<ComplexType1> LCT1 {get;set;}
}

Frankly, any client that can't deal with something like the above deserves to be retired.

like image 150
John Saunders Avatar answered Nov 10 '22 08:11

John Saunders


Formerly I would have prefered the latter, because I wasn't sure, if in cross platform situation, every SOAP client would be able to consume the complex types properly. So I thought a SOAP call, that just takes and returns (XML-)Strings will give me no headache. In the meantime I experienced there is generally no problem with the first approach at least for .Net interoperating with JAVA/AXIS and vice versa. I'm still watching to make the complex type not too complex though.

I assume that ThisMethodDoesSomething() and ThisMethodDoesSomethingElse() are atomic operations? If this not the case (ThisMethodDoesSomethingElse() requires a call to ThisMethodDoesSomething() to execute), the first approach is a no go.

like image 1
huo73 Avatar answered Nov 10 '22 09:11

huo73