B
B
bagos2015-02-25 16:52:35
WCF
bagos, 2015-02-25 16:52:35

Is it possible to pass Ilist or other collection through WCF?

Hello, how can I pass IList through wcf service?
Ilist - collection of objects of class MyClass

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniel Vygolov, 2015-03-05
@bagos

What's stopping you? The contract will look like this:

[ServiceContract]
public interface IService
{
  [OperationContract]
  List<MyClass> GetMyClassList();
}

Well, the MyClass class, as well as its properties, must be appropriately marked with attributes:
[DataContract]
public class MyClass
{
  [DataMember]
  public int Id { get; set; }
}

B
bagos, 2015-03-05
@bagos

Все так и сделано, list передается, но каждый раз приходится править reference на клиенте. Структура такая:
    [DataContract]
    public abstract class A
    {
        [DataMember]
        public int Id{get;set}
        [DataMember]
        public string Name{get;set;}

        protected A(int id,string name )
        {
            Id = id;
            Name = name;
        }

        public abstract Set(...);
        public abstract Get(...);
    }

Several more classes are inherited from this class, some of which implement abstract methods of the base class, others do not, all contain a constructor, each has its own set of fields that are also marked DataMember and DataContract classes.
The class from which others inherit also has [KnownType(typeof(AnotherClass))] attributes for child classes. And everything works, but the question remains why, when creating a servicereference for the client, it does not automatically create constructors for classes in the code and also asks to add abstract methods, although they are not used and should not be used in the client. Even if they must be there, what other attribute should be added to class A for methods so that they are automatically added to the reference?
Passed through WCF List<A>which contains all classes inherited from A
Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question