IComparable not included when serializing to WCF
I have a list that I populate on the server side. This is a User list that implements IComparable. Now that WCF is serializing the data, I'm guessing this doesn't include the CompareTo method. This is my Object class:
[DataContract]
public class User : IComparable
{
private string e164, cn, h323;
private int id;
private DateTime lastActive;
[DataMember]
public DateTime LastActive
{
get { return lastActive; }
set { laatstActief = value; }
}
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
[DataMember]
public string H323
{
get { return h323; }
set { h323 = value; }
}
[DataMember]
public string Cn
{
get { return cn; }
set { cn = value; }
}
[DataMember]
public string E164
{
get { return e164; }
set { e164 = value; }
}
public User()
{
}
public User(string e164, string cn, string h323, DateTime lastActive)
{
this.E164 = e164;
this.Cn = cn;
this.H323 = h323;
this.LastActive= lastActive;
}
[DataMember]
public string ToStringExtra
{
get
{
if (h323 != "/" && h323 != "")
return h323 + " (" + e164 + ")";
return e164;
}
set { ;}
}
public override string ToString()
{
if (Cn.Equals("Trunk Line") || Cn.Equals(""))
if (h323.Equals(""))
return E164;
else
return h323;
return Cn;
}
public int CompareTo(object obj)
{
User user = (User)obj;
return user.LastActive.CompareTo(this.LastActive);
}
}
Can I get the CompareTo method to access the client? Putting [DataMember] is not a solution as I tried it (I know ...).
Thanks in advance.
a source to share
No, CompareTo is not a member.
If you want to replicate this on the client side, either provide a client side library that adapts the client object as well as implements IComparable.
@frogbot does have the correct suggestion, but object passing is contrary to the true nature of SOA, the purpose is to talk interfaces, which is why they made it difficult to use the NetDataContractSerializer.
a source to share
Since your client and server are talking about the same technology stack (i.e. both are using .Net), use the same client side code reference (data object) as the server using *. Then the interface implementations will be intact, both assemblies will use the same data object definitions, not the server using the regular definition and the client using the definition that is generated as part of the proxy.
Sharing or reusing these assemblies is a topic that has been well covered in SO.
* this means that your data objects, such as User, are contained in a separate assembly, which is the sole purpose of that assembly. Then both your client and your server (webservice) can refer to it.
a source to share