简体   繁体   中英

How to initialize arrays in web service client

I've asked this question already this week but am rephrasing it with the hope that I can get more clearer answers.

I am working with arrays in web services and am having difficulty initialising the array within the web service for sending messages to the service.

Any insight on how to do with would be greatly appreciated.

my service definitions:

UpdateRatePackages.IService.InventoryServiceClient isc = new UpdateRatePackages.IService.InventoryServiceClient();
UpdateRatePackages.IService.UpdateRatePackagesRequest ureq = new UpdateRatePackages.IService.UpdateRatePackagesRequest();
UpdateRatePackages.IService.UpdateRatePackagesOperationResponse ores = new UpdateRatePackages.IService.UpdateRatePackagesOperationResponse();

The defined classes for the service that I am trying to send messages to

public class UpdateRatePackagesRequest
{
    public string Username;
    public string Password;
    public UpdateRatePackageRequest[] RatePackages;
}

public class UpdateRatePackageRequest
{
    public Int64 RatePackageId;
    public RateDetails[] Rates;
}

public class RateDetails
{
    public decimal Rate;
    public enum RateApplicationType { SET, INCREASE, DECREASE, INCREASE_PERCENT, DECREASE_PERCENT } ;
    public int Availability;
    public enum AvailabilityApplicationType { SET , INCREASE, DECREASE };
    public bool StopSell;
    public string Inclusions;
    public int MinimumNightStay;
    public DateTime FromDate;
    public DateTime ToDate;
}

public class UpdateRatePackageResult
{
    public Int64 RatePackageId;
    public Boolean Success;
    public string Message;
}

public class UpdateRatePackagesResponse
{
    public UpdateRatePackageResult[] Result;
}

the portion of my code that is giving me the error:

Int64 HID = 717759;
Int64 HRID = 85264;
int avail = 6;
// RateDetails.AvailabilityApplicationType val  = RateDetails.AvailabilityApplicationType.SET;
for (int i = 0; i < ureq.RatePackages.GetLength(0); i++)
{
    ureq.RatePackages[i].RatePackageId = HRID;
    for (int j = 0; j < ureq.RatePackages[j].Rates.GetLength(0); j++)
    {
        ureq.RatePackages[i].Rates[j].Availability = avail;
        ureq.RatePackages[i].Rates[j].AvailabilityApplicationType = UpdateRatePackages.IService.AvailabilityApplicationType.SET;
        ureq.RatePackages[i].Rates[j].FromDate = Convert.ToDateTime("2012-03-21");
        ureq.RatePackages[i].Rates[j].ToDate = Convert.ToDateTime("2012-03-31");
    }
   // isc.UpdateRatePackages(request);
}

the line with the error:

for (int i = 0; i < ureq.RatePackages.GetLength(0); i++)

Error Message: Object reference not set to an instance of an object.

Found this link that helped put everything in perspective.

Dynamically Build an array in c#

I declared my arrays and then like the example created new instances which I placed in for loops. The int value NoofGuests was the most useful. In my case I used NoofRates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM