簡體   English   中英

無法隱式轉換類型的Web服務響應

[英]Cannot implicitly convert type web service response

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

對於如何解決這個錯誤或者它為什么會出現這種錯誤,我將不勝感激。 謝謝

好的,從我能看到的

bk.GuestInfo是的單個實例GuestDetails

而你試圖在這里分配一個數組

bk.GuestInfo = new GuestDetails[noofBookings];

所以要么bk.GuestInfo需要是一個GuestDetails數組,要么你需要更改bk.GuestInfo = new GuestDetails[noofBookings]; 將單個實例分配給bk.GuestInfo

為什么不簡單

 bk.GuestInfo = new GuestDetails() ;

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

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

將Booking.GuestInfo的聲明更改為數組:

public GuestDetails[] GuestInfo { set; get; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM