非同期 WCF Web サービスと組み合わせて CCR (同時実行および調整ランタイム) を使用する方法を学んでいます。
これはテスト WCF サービスです。
public class Service : IService
{
private Accounts.Manager accountManager = new Accounts.Manager();
public IAsyncResult BeginGetAccount(int id, AsyncCallback callback, object state)
{
//How Do I Call the CCR Function without blocking a Thread?
throw new NotImplementedException();
}
public string EndGetAccount(IAsyncResult result)
{
//How Do I Finish the Call and Pass back the Result?
throw new NotImplementedException();
}
}
ID 番号を取得し、一致するアカウント名 (存在する場合) を返します。
一致するアカウントを見つける CCR 関数を作成しました (明らかに多くの作業が必要です。これは概念の証明にすぎません)。
結果を返すにはどうすればよいですか (グローバル ポート?)、さらに重要なこと: スレッドをブロックせずに CCR を WCF 非同期サービス コールにプラグインするにはどうすればよいですか?
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() };
//Post account?
}
connection.Close();
}