0

我在 C# Web 应用程序中构建了一个 Web 服务。我将对象列表作为 Web 服务结果返回。我需要知道如何在循环中一一阅读该项目列表。

<?xml version="1.0" encoding="utf-8"?>  
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
  <soap:Body>  
    <checkAvailabilityResponse xmlns="http://tempuri.org/">  
      <checkAvailabilityResult>  
        <Shedule>  
          <Sid>int</Sid>  
          <Fid>int</Fid>  
          <FromLocation>string</FromLocation>  
          <FromTime>dateTime</FromTime>  
          <ToLocation>string</ToLocation>  
          <ToTime>dateTime</ToTime>  
          <PriceSeatA>double</PriceSeatA>  
          <PriceSeatB>double</PriceSeatB>  
          <PriceSeatC>double</PriceSeatC>  
        </Shedule>  
        <Shedule>  
          <Sid>int</Sid>  
          <Fid>int</Fid>  
          <FromLocation>string</FromLocation>  
          <FromTime>dateTime</FromTime>  
          <ToLocation>string</ToLocation>  
          <ToTime>dateTime</ToTime>  
          <PriceSeatA>double</PriceSeatA>  
          <PriceSeatB>double</PriceSeatB>  
          <PriceSeatC>double</PriceSeatC>  
        </Shedule>  
      </checkAvailabilityResult>  
    </checkAvailabilityResponse>  
  </soap:Body>  
</soap:Envelope>

这是我尝试的方式:

SriLankanWebService.Service1SoapClient air1 = new AgentPortal.SriLankanWebService.Service1SoapClient();  
                List<Shedule> air1Response = (List<Shedule>)air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));

当我尝试时,它说:

Error   1   Cannot implicitly convert type 'AgentPortal.SriLankanWebService.Shedule[]' to 'System.Collections.Generic.List<AgentPortal.Shedule>'    D:\DCBSD\AgentPortal\AgentPortal\Home.aspx.cs   32  46  AgentPortal

我需要循环使用它。

4

1 回答 1

0

请从上述代码的最后一行更新您的代码:

List<Shedule> air1Response = (List<Shedule>)air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));

AgentPortal.SriLankanWebService.Shedule[] = air1.checkAvailability(drpFrom.SelectedValue.ToString(), drpTo.SelectedValue.ToString(), DateTime.Parse(txtDepartOn.Text));

这将解决问题。

于 2012-10-25T12:56:50.293 回答