Question

Can we send a Generic List ( List) as a parameter to a WCF OperationContract?

Seems like the only way to do it is to encapsulate the List as a DataMember inside another Class and specify the class as a DataContract:

But that doesn't look right to me. Is there any other way?

EDIT1:
intended Signature:

[OperationContract]  
List<int> OperationName(List<CustomObject> objects);  

This translates to CustomObject[] at the client. I am currently passing CustomObject[] from my client and it works fine, but I want to know why I can not pass

  List <CustomObject> 

which gives me a compile error saying there is no overloaded version of the function which takes the specified parameters (type mismatch error)

EDIT 2:
Related Questions:
1) I should be able to control this from the service itself. What if I am exposing my service to the entire world and the wsdl/Proxy is the only way they would know of the signature of my OperationContract?
2) What if I want to use both System.Array and System.Generic.List in different Operation Contracts in the same Service Contract?

Était-ce utile?

La solution

List is an advanced type and may not be available to all the programming paradigms. Array, in comparision is perhaps available in all the programming paradigm. hence by default the translation will fall to array for a proxy wsdl

Now in this case, If you are sure that your client is .Net, you can change the client to use List. Since the service does not know what client's programming language is, the current design of svcutil where client decides whether it uses list or array is correct. If you make this setting available in service, you are ruling out clients which does not have the concept of List

Coming to your second question, as long as your operation contract names are different, you will be able to use the array and list distictly in the same service. Also note, OOP concepts are restricted in SOA, which means you can't have polymorphic methods.

the following question has more details about OOP and SOA

WCF Object Design - OOP vs SOA

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top