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;}
}
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);
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);