Calling a web service that accept array or list of a class in Java

I want to create a web service using C#. In web service I have a web method that accept list of a specific class:

[DataContract]
public class CompositeType
{
    string stringValue = "Hello ";

    [DataMember]
    public string StringValue
    {
        get { return stringValue; }
        set { stringValue = value; }
    }

    [DataMember]
    public List<Product> Products { get; set; }
}

[DataContract]
public class Product
{
    [DataMember]
    public int PID { get; set; }

    [DataMember]
    public string PName { get; set; }
}

and my web method:

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

I want to publish this service using BasicHttpBinding that Java users can call it too. Now since the Java programmer is not around me, I wanted to ask those who have the experience to do this :

1) Can Java programmers call my web method that accept List<Product>?

2)Should I change List to Array?

Thanks for you contribution

2 answers

  • answered 2018-11-07 20:38 chrylis

    Presumably your HTTP API serializes this as JSON (or maybe XML). In either case, libraries such as Jackson can handle it just fine, and most REST clients will even handle that part automatically. Standards compliance is the rule, and so as long as your List<Product> is converted to/from a regular JSON array, everything should work smoothly.

    JSON doesn't have separate list types, just the plain array, so either array or list-based serialization should be equivalent.

    As a note, most APIs use either camelCase or snake_case for properties, so your property names (in JSON) would be expected to be stringValue, products, pid, and pName.

  • answered 2018-11-08 14:13 Abraham Qian

    As with .Net client calling WCF using the Svcutil tool, most Java users use the asis2 library which is a webservice engine to invoke web service.
    WebService is a specification that any service that implements it can be called WebService, they use WSDL to describe the service details, they use SOAP message based on XML to communicate, which is used for generating the client proxy class. The reason why WCF can be called across service boundaries by various platforms is that it is also a web service. Although there may be different data types on various platforms, as long as we specify how to represent it in XML and how to serialize it, the service can be called correctly by others platforms, By default, List is specified to be serialized using a one-dimensional array.