I have a solution with 3 projects:
The Models project has POCO classes that reference my database table like below:
[DataContract]
[Table("users")]
public class User
{
public User()
{
}
[DataMember]
[Key, Column("userid", TypeName = "int")]
public Int32 UserId { get; set; }
[DataMember]
[Column("username", TypeName = "varchar")]
public String UserName { get; set; }
The WCF Service Project has a reference to Models in order to return the Model from a Method like below:
public User ValidateUser(string organization, string userName, string password)
{
Model.Poco.User user = new Model.Poco.User();
user.UserId = 1;
user.BoardMember = true;
user.Email = "test@yahoo.com";
user.FirstTimeLogin = false;
user.IsActive = true;
user.Notes = "notes";
user.Password = "xxxxxx";
user.UserName = "user1";
return user;
}
Now, my client has a Service Reference to the WCF Service and the code to call it is like below:
private void button1_Click(object sender, EventArgs e)
{
WCFService.Service1Client client = new WCFService.Service1Client();
var user = client.ValidateUser("test", "test", "test");
}
It's working ok like this, If I navigate "user" variable It has all the object properties from the WCF Service, but what I want to do is to have:
Model.Poco.User user = client.ValidateUser("test", "test", "test");
But if I do this Im getting an error that its not possible to convert from: WCFService.User to Model.Poco.User.
Any clue on how can I convert the serialized object to the native one. Note, that Im using the same object on both client and WCF Service because Im referencing the *Models project on both.*
Appreciate any help in advance!!
When you generate the service reference in the client project, check the option to reuse types in referenced assemblies. Otherwise the tool will generate new classes based on the WSDL as part of the service reference.