WCF IList is deserialized as an array. How to make it writable by list (ArrayList)?

I have a client-server application, parts of which "talk" to each other through WCF (netTcp binding).

I have a DataContract that has 1 field of a third-party class:

[Serializable]
public class MyResult{
  public ThirdPartyResult Result {get;set;}

  /* other fields */
}

Using reflection, I see the following:

[Serializable]
public class ThirdPartyResult {
  private IList result;

  public IList Result
  { 
    get { return result ?? (result = new ArrayList());}
  }
}

When I call the server from the client, I have resultboth ArrayListon the server. When the client comes to the client, the field resultbecomes an array of a fixed size.

I have not used , adding a link to the service, but I use a shared assembly and simple

ChannelFactory<IMyContract>.CreateChannel(new NetTcpBinding("Configuration.Name"), address);

UPDATE: service contract

[ServiceContract]
[ServiceKnownType(typeof(ArrayList))]
[ServiceKnownType(typeof(ThirdPartyResult))]
public interface IMyContract
{
   MyResult GetResult();
}

Now the question is:
How can I tell WCF to use ArrayListinstead Array?


( )
, ArrayList, . , . , , , .

        if (thirdParty.Results != null && thirdParty.Results.IsFixedSize)
        {
            var results = new ArrayList(thirdParty.Results);

            // Finding result by ReferenceEquals to not be tight to private variable name
            var resultsField = thirdParty.GetType()
                .GetFields(BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic)
                .Where(f => ReferenceEquals(f.GetValue(thirdParty), thirdParty.Results))
                .FirstOrDefault();

            if (resultsField != null)
                resultsField.SetValue(thirdParty, results);
        }
        thirdParty.AddResult(otherChild);
+5
4

( ) Visual Studio, , "Deserialize arrays as", //etc. , , .

+1

:

WCF:

: , .

[DataMember]
private List<Person> members = new List<Person>();

:

[DataMember]
private Iist<Person> members = new Iist<Person>();

[DataMember()]
public IList<Person> Feedback {
    get { return m_Feedback; }
    set {
        if ((value != null)) {
            m_Feedback = new List<Person>(value);

        } else {
            m_Feedback = new List<Person>();
        }
    }
}
+1

, - . ; result , , ArrayList:

private ArrayList result;
public IList Result { 
  get { return result ?? (result = new ArrayList());}
}

List<T> [DataContract]/[DataMember] .., ...

0

, ThirdPartyResult

 public static class ThirdPartyResultExtension
  {
    public static ArrayList ResultsAsArrayList(this ThirdPartyResult d)
    {
      ArrayList list = new ArrayList();
      list.AddRange(d.Result);
      return list;
    }

  }

  public class ThirdPartyResult
  {
    private IList result;

    public IList Result
    {
      get { return result ?? (result = new ArrayList()); }
    }
  }

 ThirdPartyResult r;
     ArrayList arrlist = r.ResultsAsArrayList();
0

All Articles