現在、ボタン用に次のコードがあります。SilverlightApplication2.ServiceReference2.Employee
ユーザーが選択したテキスト文字列の代わりに、メッセージ ボックスが表示されます。コンボボックスの項目は、WCF サービスによって設定されています。その結果、非同期呼び出しに渡すことができません。ユーザーが選択した文字列を取得するにはどうすればよいですか?
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
object selectedItem = comobo1.SelectedItem.ToString();
MessageBox.Show(selectedItem.ToString());
var proxy = new Service1Client();
proxy.GetAllEmployeesCompleted += proxy_GetAllEmployeesCompleted;
proxy.GetAllEmployeesAsync(selectedItem.ToString());
}
私のサービス参照は次のようになります
パブリック クラス ドロップダウン {
[OperationContract]
public ObservableCollection<Employee> GetAllBrands()
{
var empstwo = new ObservableCollection<Employee>();
string connect = ConfigurationManager.ConnectionStrings["yoyo"].ToString();
using (var con = new OdbcConnection(connect))
{
//now you can try
//wait. To accept a param from main page, u need to create a method to accept that param first.
//I think you should put this in service1.svc.cs
string query = "Select distinct(brand) FROM pivottable";
var cmd = new OdbcCommand(query, con);
con.Open();
using (var dr = cmd.ExecuteReader())
{
while (dr.Read())
{
var emp = new Employee();
emp.ComboData = dr.GetStringOrNull(0);
empstwo.Add(emp);
}
}
}
return empstwo;
}
}
これは従業員クラスです。この文字列で、ComboData はドロップダウン リストに入力するブランドのリストを保持します
public class Employee
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public Uri ImageURI { get; set; }
public string ComboData { get; set; }
}