Reputation: 57
Is there any possibility to send DbConnection as a parameter of OperationConstract in WCF? Because I get exception "Type System.Data.SqlClient.SqlConnection with data contract name SqlConnection:http://schemas.datacontract.org/2004/07/System.Data.SqlClient. is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer."
Upvotes: 0
Views: 242
Reputation: 1063609
No, that is never going to work. A SqlConnection
is a wrapper around a local connection which only makes sense in that one AppDomain
, in that one process, on that one machine. At best you could send the connection string, but that doesn't guarantee that the other user can connect (line-of-sight to the server / firewalls, the account identity, etc).
Frankly I would find it questionable to want to do that. A service should expose data, not internal mechanics like internal connections.
Upvotes: 5