无法隐式转换类型的Web服务响应

时间:2012-09-26 04:08:25

标签: c# arrays web-services implicit-conversion

我有一个调用另一个客户端Web服务的Web服务。

以下是我用于从中提取预订详细信息的代码。

ResMsg.GetBookingsOperationRequest request = new ResMsg.GetBookingsOperationRequest();

        int noofBookings = 3;
        DateTime checkInDate;
        DateTime checkOutDate;
        string bookingStatus;
        string Notes;
        int adults;
        int children;
        Int64 bookingID;
        string bookingSource;
        DateTime bookingDate;

        string resResult;
        using (var proxy = new ResMesg.ResonlineMsg.InventoryServiceClient())
        {

            var result = proxy.GetModifiedBookings(request);
            ResMsg.Booking[] bookings= new ResMsg.Booking[noofBookings];
            result.Bookings = new ResMesg.ResonlineMsg.Booking[noofBookings];
            result.Bookings = bookings;

            for (int i = 0; i < bookings.Length; i++)
            {
                Booking bk = new ResMesg.ResonlineMsg.Booking();
                result.Bookings[i]=bk;

                bookingID = bk.BookingId;
                checkInDate = bk.CheckInDate;
                checkOutDate = bk.CheckOutDate;
                adults = bk.Adult;
                children = bk.Children;
                bookingStatus = bk.BookingStatus;
                Notes = bk.Note;
                bookingSource = bk.BookingSource;
                bookingDate = bk.BookingDate;

                bk.GuestInfo = new GuestDetails[noofBookings]; ** Place where error is referring to.GuestDetails is an array. GuestInfo is an instance of GuestDetails.

            }


           return "Success";


    }
  

错误1无法隐式转换类型   'ResMesg.ResonlineMsg.GuestDetails []'到   'ResMesg.ResonlineMsg.GuestDetails'

**更新: GuestDetails的数据类型

Field             Data Type      Description
Name              string         Guest's full name. 
Address           string         Guest's address. 
EmailAddress      string         Guest's email address. 
PhoneNumber       string         Guest's phone number. 

从对象浏览器中复制的GuestDetails的定义

 public GuestDetails GuestInfo { set; get; }
        (Member of Booking)

对于如何解决这个错误或者它为什么会出现这种错误,我将不胜感激。感谢

3 个答案:

答案 0 :(得分:1)

好的,从我能看到的

bk.GuestInfoGuestDetails

的单个实例

你试图在这里为这个分配一个数组

bk.GuestInfo = new GuestDetails[noofBookings];

因此,bk.GuestInfo需要是GuestDetails的数组,或者您需要更改bk.GuestInfo = new GuestDetails[noofBookings];以将单个实例分配给bk.GuestInfo

答案 1 :(得分:1)

为什么不简单

 bk.GuestInfo = new GuestDetails() ;

第19,20,21行看起来也在做同样的事情。

 var details = new GuestDetails[noofBookings] ; 
// fill details array before this..
 bk.GuestInfo = details[noofBookings];

答案 2 :(得分:0)

将Booking.GuestInfo的声明更改为数组:

public GuestDetails[] GuestInfo { set; get; }