I'm rather new to WCF, and have created created a service with the following two methods:
[ServiceContract]
public interface IDB
{
[OperationContract]
DbResponse<Student> AddStudent(string pnr, string firstName, string lastName, string userName, string email, string cls);
[OperationContract]
DbResponse<List<Student>> FindStudent(string searchString);
}
The DbResponse is a generic class:
[DataContract]
public class DbResponse<T>
{
[DataMember]
public DbStatus Status { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public T Data { get; set; }
}
where DbStatus is an enum:
[DataContract]
public enum DbStatus
{
[EnumMember]
Ok,
[EnumMember]
Warning,
[EnumMember]
Failed
};
This works fine, except that on the client side, since adding the generic property to DbResponse, I can no longer use the following:
string filter = "Foo";
DBClient dbc = new DBClient();
WebInterface.Services.DbResponse response = dbc.FindStudent(filter);
Instead, according to Intellisense, I have to use the strange-looking (and ugly) type:
WebInterface.Services.DbResponseOfArrayOfStudentL1_PcKk2u response = dbc.FindStudent(filter);
I would greatly appreciate it if anyone could shed some light over why this happens and if (and how) I can use a "cleaner" type name.
Ok, I found out that the hash can be overridden by using the Name property in the DataContract attribute (http://jeffbarnes.net/blog/post/2007/05/10/wcf-serialization-and-generics.aspx):
[DataContract(Name = "DbResponse{0}"]
public class DbResponse<T>
{
[DataMember]
public DbStatus Status { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public T Data { get; set; }
}
This will still output e.g. DbResponseOfArrayOfStudent, but at least there is no ugly hash, so I guess I will have to live with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With