0

I have this error appearing in my web service and even though I'v had a look at the articles on the null issue, I am not able to find how to fix this error

this is my code:

    SendInvUpdate.InvServices.UpdateRatePackagesRequest urq = new SendInvUpdate.InvServices.UpdateRatePackagesRequest();
    SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse ors = new SendInvUpdate.InvServices.UpdateRatePackagesOperationResponse();


    protected void Page_Load(object sender, EventArgs e)
    {
        Int64 HID = 819942;
        Int64 HRID = 154482;

        SendInvUpdate.InvServices.UpdateRatePackagesRequest request = new SendInvUpdate.InvServices.UpdateRatePackagesRequest();

        ChannelManagerAccount account = new ChannelManagerAccount();
        request.HotelId = HID;

        int avail = 4;
        DateTime frodte = Convert.ToDateTime("2012-04-12");
        DateTime todte = Convert.ToDateTime("2012-04-30");
        int NoofRatePackages = 3;
        UpdateRatePackageRequest[] RatePackages = new UpdateRatePackageRequest[NoofRatePackages];
        string res;
        request.RatePackages = new UpdateRatePackageRequest[NoofRatePackages];
        request.RatePackages = RatePackages;

        UpdateRatePackageRequest rp = new UpdateRatePackageRequest();

        for (int i = 0; i < NoofRatePackages; i++)
        {        
            rp.RatePackageId = HRID;        

            RateDetails[] Rates = new RateDetails[NoofRatePackages];

            rp.Rates = new RateDetails[NoofRatePackages];
            rp.Rates = Rates;

            RateDetails rd = new RateDetails();

            for (int j = 0; j < NoofRatePackages; j++)
            {
                rd.Availability = avail;

                rd.AvailabilityApplicationType = SendInvUpdate.InvServices.AvailabilityApplicationType.SET;

                rd.FromDate = frodte;

                rd.ToDate = todte;

            }

        }

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

        res = ors.Results.ToString();          
    }

I know that it has something to do with the RateDetails array and initialising the value of the RateDetails to that instant of request but I am not sure how or what to do with regards to that. In debug mode when looking at values of rp there are no values for rp.Rates[0],rp.Rates[1],rp.Rates[2] also RatePackages[0],RatePackages[1],RatePackages[2] are also null so I have a strong feeling thats where my problem is but I don't have a clue on how to fix.

Would be grateful for any sort of insight to where I've gone wrong!

2
  • Where is ores defined? Commented Apr 10, 2012 at 21:21
  • Thanks for that, I have editted, should be ors defined on top with the new instance to my web service Commented Apr 10, 2012 at 21:23

1 Answer 1

2

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;
            ....
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for that, it didn't work, I have editted the code to show what it looks like after your suggestion.
I expect that, if you set a breakpoint on the offending line, and inspect the request and the icc vars you will see that they are not null. So, if you execute the line and your code breaks with an unhandled exception, this means that the error is internal to the webservice method UpdateRatePackages
Thanks @steve I have set a breakpoint and found there are no nulls and I have also revised my question hoping it clarifies my problem for everyone.
I got that from one of the examples of arrays in webservices in one of the questions asked on this site last week but I don't have the link on me right now. Its works fine because I'm able to get the value for rp.RatePackageId = HRID; as 154482. It is after I call an instance of RateDetails that I get nulls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.