我的问题是 AddExcursionAsync 不起作用,它显示 CommunicationException。在控制台应用程序中,此代码运行良好。但在 Silverlight 中它会出错。函数 AddListOgTourNumbersAsync 和 GetListOfTourNumberAsync 工作正常。我在哪里犯了错误?
代码:
private AdminServiceClient client;
public AddExcursionDialog()
{
InitializeComponent();
DurationElement.Value = new DateTime();
client = new AdminServiceClient();
client.GetListOfTourNumberCompleted += new EventHandler<GetListOfTourNumberCompletedEventArgs>(GetListOfTourNumber);
client.AddListOgTourNumbersCompleted += new EventHandler<AsyncCompletedEventArgs>(AddListOfTourNumbers);
client.AddExcursionCompleted += new EventHandler<AsyncCompletedEventArgs>(AddExcursion);
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
excursion = new Excursion();
excursion.Name = NameText.Text;
excursion.Cost = Convert.ToDouble(CostText.Text);
excursion.Place = PlaceText.Text;
excursion.Duration= (DateTime)DurationElement.Value;
excursion.Agency_id = tour_names[AgencyCB.SelectedValue.ToString()];
excursion.MaxPpl = Convert.ToInt32(MaxPplText.Text);
client.GetListOfTourNumberAsync();
client.AddExcursionAsync(excursion);
client.AddListOgTourNumbersAsync(tour_id, excursion.NumberOfList);
this.DialogResult = true;
}