I am having a problem in MySql.Data.MySqlClient.MySqlTransaction in a Windows Communication Foundation Server Application.
I am using the MySqlTransaction inside the method of the class that implements the ServiceContract Interface and it throws this error when I try to run the service:
System.Runtime.Serialization.InvalidDataContractException: Type 'MySql.Data.MySqlClient.MySqlTransaction' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.
My code in WCF service was simmilar to this:
[ServiceContract]
public interface IDALService
{
MySqlCommand Command { [OperationContract] get; [OperationContract] set; }
[OperationContract]
void Execute(string cmdText);
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class DALService : IDALService
{
public MySqlCommand Command { get; set; }
public DALService()
{
Command = null;
}
public void Execute(string cmdText)
{
MySqlCommand SQLCom = this.Command??new MySqlCommand();
SQLCom.CommandText = cmdText;
if (this.Command == null)
{
SQLCom.CommandType = CommandType.Text;
SQLCom.Connection = new MySqlConnection(/* ... */);
SQLCom.Connection.Open();
SQLCom.Transaction = SQLCom.Connection.BeginTransaction();
}
if (this.Command == null)
{
try
{
SQLCom.ExecuteScalar();
SQLCom.Transaction.Commit();
}
catch { SQLCom.Transaction.Rollback(); throw; }
finally { SQLCom.Connection.Close(); }
}
else SQLCom.ExecuteScalar();
}
}
The error occur just by typing the http://localhost:1257/DALService.svc in my web browser.
I am using Framework 4, code in C#, in Microsoft Visual Studio 2010 Pro.
Please help. Thanks in advance.