0

我有一个 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)

对于如何解决此错误或出现此错误的原因,我将不胜感激。谢谢

4

3 回答 3

1

好的,据我所见

bk.GuestInfo是单个实例GuestDetails

而您试图在此处为其分配一个数组

bk.GuestInfo = new GuestDetails[noofBookings];

所以要么bk.GuestInfo需要是一个数组,GuestDetails要么你需要更改bk.GuestInfo = new GuestDetails[noofBookings];为将单个实例分配给bk.GuestInfo

于 2012-09-26T04:17:11.237 回答
1

为什么不简单

 bk.GuestInfo = new GuestDetails() ;

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

 var details = new GuestDetails[noofBookings] ; 
// fill details array before this..
 bk.GuestInfo = details[noofBookings];
于 2012-09-26T04:20:49.893 回答
0

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

public GuestDetails[] GuestInfo { set; get; }
于 2012-09-26T04:28:44.443 回答