Reputation: 646
My WCF interface looks like this:
[ServiceContract]
public interface IService
{
[OperationContract]
Foo<String>[] Test();
}
The Foo<T>
class looks like this:
[DataContract(Name = "FooOf{0}")]
public class Foo<T>
{
public T Value { get; set; }
}
I publish the WCF service and add service reference to my client code, then I use this method like this:
var client = new ServiceClient(new BasicHttpBinding(), new EndpointAddress(@"http://myServer:port/Service.svc"));
FooOfString[] result = client.Test();
However, I cannot access the properties of the generated classes, for example, I cannot do this:
var value = result[0].Value; // cannot access property, does not compile
I am able to do the EXACT same thing by removing the [DataContract(Name = "FooOf{0}")]
part of my Foo<T>
class and I can access the properties, the problem is the name of the generated class which changes to FooOfStringCHtiIp13
and that looks ugly, I'm trying to rename it to something a bit more readable. This operation, however, now works:
FooOfStringCHtiIp13[] result = client.Test();
var value = result[0].Value; // can access, compiles
It feels like something does not get serialized and I am not using this correctly. Any idea how to achieve this correctly?
Upvotes: 3
Views: 1147
Reputation: 646
Solved my problem, the issue was in my Value
property of Foo<T>
class, I had to add DataMemberAttribute
to my property:
[DataContract(Name = "FooOf{0}")]
public class Foo<T>
{
[DataMemberAttribute(Name = "Value")]
public T Value { get; set; }
}
Upvotes: 1