本周我已经问过这个问题,但我正在改写它,希望能得到更明确的答案。
我正在使用Web服务中的数组,并且很难在Web服务中初始化数组以向服务发送消息。
非常感谢任何有关如何处理的见解。
我的服务定义:
UpdateRatePackages.IService.InventoryServiceClient isc = new UpdateRatePackages.IService.InventoryServiceClient();
UpdateRatePackages.IService.UpdateRatePackagesRequest ureq = new UpdateRatePackages.IService.UpdateRatePackagesRequest();
UpdateRatePackages.IService.UpdateRatePackagesOperationResponse ores = new UpdateRatePackages.IService.UpdateRatePackagesOperationResponse();
我尝试将消息发送到
的服务的已定义类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;
}
我的代码中给出错误的部分:
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);
}
错误行:
for(int i = 0; i&lt; ureq.RatePackages.GetLength(0); i ++)
错误讯息:Object reference not set to an instance of an object.
答案 0 :(得分:0)
发现此链接有助于将所有内容放在透视中。
Dynamically Build an array in c#
我声明了我的数组,然后像示例一样创建了我放入for循环的新实例。 int值NoofGuests是最有用的。就我而言,我使用了NoofRates