سؤال

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."

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top