I am learning how to use CCR (Concurrency and Coordination Time) in conjunction with the WCF asynchronous web service.
This is a test WCF service:
public class Service : IService
{
private Accounts.Manager accountManager = new Accounts.Manager();
public IAsyncResult BeginGetAccount(int id, AsyncCallback callback, object state)
{
throw new NotImplementedException();
}
public string EndGetAccount(IAsyncResult result)
{
throw new NotImplementedException();
}
}
It will accept the identification number and return the name of the corresponding account (if any)
I wrote the CCR function, which should find the appropriate accounts, (obviously, a lot of work is required - this is just a proof of concept) This is where I stick up.
How to transfer results (global port?) And more importantly: how to connect CCR to asynchronous call of WCF service without blocking the flow?
public IEnumerator<ITask> GetAccount(int id)
{
SqlDataReader reader = null;
SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=BizData;Integrated Security=True;Async=True;");
string query = "SELECT * FROM Account WHERE AccountID = @AccountID";
SqlCommand command = new SqlCommand(query, connection);
SqlParameter accountID = new SqlParameter("AccountID", id);
command.Parameters.Add(accountID);
connection.Open();
yield return Arbiter.Choice(SQLAdapter.GetReader(command),
delegate(SqlDataReader r) { reader = r; },
delegate(Exception e) { Console.Write("Failed to get SQL data"); });
if (reader == null) yield break;
while (reader.Read())
{
Account account = new Account { ID = Convert.ToInt32(reader["AccountID"]),
Name = reader["Account"].ToString(),
ParkingNo = Convert.ToInt32(reader["ParkingNo"]),
Password = reader["Password"].ToString() };
}
connection.Close();
}
source
share