I’m making a asmx web service and I use LinqToSQL to deal with database.
It’s seems to be easy for me to use LinqToSQL generated classes as arguments or return values in web methods.
Like this:
[WebMethod]
public OperationResult Meet_ListMeets(string clientToken, out meet[] meets)
{
ServiceMeet s = new ServiceMeet(sqlCon, clientToken);
return s.ListMeets(out meets);
}
Where “meet” is a LinqToSQL class.
I found that meet class is exposed as WSDL complex type including all dependencies (such as other classes which is referent to meet by the foreign keys in database).
Main question is “is it a good practice to use classes that way?”. What about a security?
Should I use wrapper-classes to hide my entity structure?
Not a good practice, and you’ll most likely run into problems at some point. Not to mention the overhead of all that extra cruft down the wire.
What I’ve done in the past is make a “inbetween” model with just the fields I need to actually send across the wire, and the map them back to the real object when they come in. You can do the mapping manually or with one of the many mapping toolkits for .NET (look in NuGet).