Suppose I have a linq to sql class. I want to return the object datacontext throught wcf. I have already made the database unidirectional.I put the WCF works getString() just to demonstrate that the wcf service works if I comment out everything about the ToolboxDataContext.
public interface Database()
{
[OperationContract]
ToolboxDataContext getCtx();
[OperationContract]
string getString();
}
public class test: Database
public ToolboxDataContext getCtx()
{
ToolboxDataContext ctx = new ToolboxDataContext ();
return ctx;
}
public string getString()
{
return "WCF WORKS";
}
[DataContract]
public class Testing //my svc file
{
[DataMember]
public ToolboxDataContext ctx;
[DataMember ]
public string Id;
}
Is your
ToolboxDataContextan Entity Framework DataContext? Assuming it is…I’m not sure sending the entire data context object over the wire is really what you want to do. It likely won’t “work” from the client that receives it. Like, you won’t be able to run a Linq statement against it and hit the database pr anything… You might just want to return the data entities (not the entire context) as shown here (MSDN), or perhaps consider using WCF Data Services instead?
I guess a good question is; what is the client going to do with the DataContext?