问题
I'm using my own WCF proxy with ClientBase, I want to do somthing like the ct attribute in the svc util, and tell the proxy to return the List<> collection type.
i cant use List<> because the entities managed by nhibernate so i have to use IList
the proxy was not generated with svcutil.... i wrote it my self.
How can I do this?
回答1:
Unfortunately, when the declared type in the contract is an interface type like IList, there is no way to control what type WCF will actually instantiate (in practice, it will be an array).
See http://msdn.microsoft.com/en-us/library/aa347850.aspx:
"During deserialization, when the declared type is an interface, the serialization engine chooses a type that implements the declared interface, and the type is instantiated. The known types mechanism (described in Data Contract Known Types) has no effect here; the choice of type is built into WCF."
回答2:
You should be able to manually fix all the references in the proxy from 'array' to 'list' - essentially just a tedious find and replace.
But if, for some reason, that doesn't work you could just write a wrapper around your proxy class, which translates the array into a list. This might be easier anyway:
private object[] myProperty
public List<object> MyProperty
{
get
{
return p.ToList();
}
set
{
//initialise if necessary
p = value.ToArray();
}
}
来源:https://stackoverflow.com/questions/1537958/manually-change-the-clientbase-collection-type-from-array-to-list