1
我想獲得國家的名字形成列表中的一個領域,並把他們的組合框:WCF - 列表組合框
public TravelAgencyResponse GetInformation(TravelAgencyRequest request)
{
TravelAgencyResponse response = new TravelAgencyResponse();
// response.Offers = new OfferDto();
response.Offers = new List<DataTransferObjects.OfferDto>();
response.Offers.Add(new DataTransferObjects.OfferDto()
{
IdOffer = 0,
KindOfAccommodation = "Hotel",
Country = "Spain",
});
response.Offers.Add(new DataTransferObjects.OfferDto()
{
IdOffer = 1,
KindOfAccommodation = "Hotel",
Country = "Italy",
});
response.ThisOffer = (from offer in response.Offers
where offer.Country == request.Country
select offer).FirstOrDefault();
return response;
}
我認爲我可以使用LINQ沒有FirstOrDefault()但我在這種情況下不能這樣做。
private void button1_Click(object sender, EventArgs e)
{
Uri baseAddr = new Uri("http://localhost:1232/TravelAgencyService/SimpleTravelAgencyService/");
ChannelFactory<ITravelAgencyService> factory = new ChannelFactory<ITravelAgencyService>(new WSHttpBinding(),
new EndpointAddress(baseAddr));
ITravelAgencyService proxy = factory.CreateChannel();
var response = proxy.GetInformation(
new TravelAgencyService.Messages.TravelAgencyRequest()
{
Country = textBox1.Text
});
comboBox1.Items.Add(response.ThisOffer.Country);
listBox1.Items.Add(response.ThisOffer.Country);
}
我試圖把這些信息組合框那樣:
comboBox1.Items.Add(response.ThisOffer.Country);
,我只給出了第一個國家或類似的:
comboBox1.Items.Add(response);
,我沒有得到任何東西。
我與WCF的第一步!請理解,請!
但我不能使用List我的數據 - _ error不能將類型'System.Linq.IOrderedEnumerable '隱式轉換爲'System.Collections.Generic.List '。存在明確的轉換(您是否缺少演員?)_ 而且我得到ComboBox不包含_ItemsSource_的定義的信息,_DataSource_是否一樣? –
Quicki
@KlaudiaW。我更新了語句,你也需要調用'ToList',至於'ComboBox'不包含ItemsSource的定義:我認爲你使用的是WPF,我的錯誤。是的,你應該可以使用'DataSource',我會更新答案。 –