WCF: get generic type object (e.g. MyObject<T>) from remote machine
Posted
by Aaron
on Stack Overflow
See other posts from Stack Overflow
or by Aaron
Published on 2010-06-03T03:05:43Z
Indexed on
2010/06/03
3:14 UTC
Read the original article
Hit count: 204
I have two applications that are communicating through WCF.
On the server the following object exists:
public class MyObject<T>
{
...
public Entry<T> GetValue()
}
Where Entry<T>
is another object with T Data
as a public property. T could be any number of types (string, double, etc)
On the client I have ClientObject<T>
that needs to get the value of Data
from the server (same type).
Since I'm using WCF, I have to define my ServiceContract as an interface, and I can't have ClientObject<T>
call Entry<T> GetMyObjectValue (string Name)
which calls GetValue
on the correct MyObject<T>
because my interface isn't aware of the type information.
I've tried implementing separate GetValue functions (GetMyObjectValueDouble, GetMyObjectValueString) in the interface and then have ClientObject
determine the correct one to call. However, Entry<T> val = (Entry<T>)GetMyObjectValueDouble(...);
doesn't work because it's not sure about the type information.
How can I go about getting a generic object over WCF with the correct type information? Let me know if there are other details I can provide.
Thanks!
© Stack Overflow or respective owner