0

I have My Interface as :

 [ServiceContract]
    interface IDataRetrieve
    {
        [OperationContract]
        SqlConnection CreateSQLConnection(string connectionString);
        //DataSet GetSQLData(SqlConnection sqlConnection);
    }

and the Implementation as:

[DataContract]
    public class DataRetriever:IDataRetrieve
    {
        [OperationBehavior]
        public SqlConnection CreateSQLConnection(string connectionString)
        {

            SqlConnection connection = new SqlConnection(connectionString);
            return connection;
        }
}

Now while trying to access the service , getting unaccessible error.

The moment I change the return type of the method as void , service starts working. What am I doing wrong?

1
  • 1
    why do you want to return SqlConnection? Commented Jan 10, 2014 at 7:53

1 Answer 1

3

SqlConnection is not serializable so you can't return it from WCF service method. Also it has no sense because you will not be able to connect to sql server from another machine using this connection, you will need to create a new one. If passing a "connection" is a necessity you can pass a connection string and other settings necessary to create a connection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.