Object reference not set to an instance of an object - webservices

╄→尐↘猪︶ㄣ 提交于 2019-12-02 07:59:39

Move the initialization of icc service reference inside your page_load code as

SendInvUpdate.InvServices.InventoryServiceClient icc = new SendInvUpdate.InvServices.InventoryServiceClient(); 
ors = icc.UpdateRatePackages(request); ( Line where the error appears)

I'm not an expert in asp.net but you can't base your code on global vars if you don't save them in some persistent container (search about SESSION, VIEWSTATE)

EDIT: also something seems wrong here

   UpdateRatePackageRequest[] RatePackages = new UpdateRatePackageRequest[NoofRatePackages]; 
   string res; 
   request.RatePackages = new UpdateRatePackageRequest[NoofRatePackages]; 
   request.RatePackages = RatePackages; 

should be only request.RatePackages = new UpdateRatePackageRequest[NoofRatePackages]; ?

EDIT2: You send to the InventoryServiceClient an object request that contains an array of UpdateRatePackageRequest, but after creation of the array you don't set any instance of UpdateRatePackageRequest. So I suppose the InventoryServiceClient fails when reading the values from the array. I will try to change your for loop in this way

   for (int i = 0; i < NoofRatePackages; i++)       
   {               
        UpdateRatePackageRequest rp = new UpdateRatePackageRequest(); 
        request.RatePackages[i] = rp;
        ....

Same error with RateDetails. You create the array, but don't set any value of your array with an actual instance of RateDetails

        for (int j = 0; j < NoofRatePackages; j++) 
        { 
            RateDetails rd = new RateDetails();  
            rp.Rates[j] = rd;
            ....
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!