0

I am currently pulling a httpwebrequest for warranty information. I have tested each section for information and it worked. Once I put it into a class it failed.

My question is, how can I effectively call the Device class ?

    Dell computerRequest = new Dell(apiKey);
            XDocument xlTest = new XDocument();
            xlTest = computerRequest.XmlResponse(txtTag.Text.Trim());

            XNamespace getAssetWarrantyA = "http://schemas.datacontract.org/2004/07/Dell.AWR.Domain.Asset";
            XNamespace getAssetWarrantyI = "http://www.w3.org/2001/XMLSchema-instance";

            List<Device> xlAsset = (from asset in xlTest.Descendants(getAssetWarrantyA + "Response")
                          select new Device()
                          {
                              DeviceInfo = (from defaultInfo in asset.Descendants(getAssetWarrantyA + "DellAsset")
                                            select new DeviceBase()
                                            {
                                                Product = (string)asset.Descendants(getAssetWarrantyA + "MachineDescription").FirstOrDefault(),
                                                OrderNumber = (string)asset.Descendants(getAssetWarrantyA + "OrderNumber").FirstOrDefault(),
                                                ServiceTag = (string)asset.Descendants(getAssetWarrantyA + "ServiceTag").FirstOrDefault(),
                                                ShipDate = (string)asset.Descendants(getAssetWarrantyA + "ShipDate").FirstOrDefault()
                                            }).ToList(),
                               WarrantyInfo = (from warranty in asset.Descendants(getAssetWarrantyA + "Warranty")
                                               select new Warranty()
                                               {
                                                   Service = (string)warranty.Descendants(getAssetWarrantyA + "ServiceLevelDescription").FirstOrDefault(),
                                                   Provider = (string)warranty.Descendants(getAssetWarrantyA + "ServiceProvider").FirstOrDefault(),
                                                   StartDate = (string)warranty.Descendants(getAssetWarrantyA + "StartDate").FirstOrDefault(),
                                                   EndDate = (string)warranty.Descendants(getAssetWarrantyA + "EndDate").FirstOrDefault(),
                                                   TypeOfWarranty = (string)warranty.Descendants(getAssetWarrantyA + "EntitlementType").FirstOrDefault()
                                               }).ToList(),
                          }).ToList();



**//FAILS -- No object set to reference**
            Device testDevice = new Device();
            MessageBox.Show(testDevice.WarrantyInfo.Count.ToString());

            dtGrdWar.DataSource = xlAsset.ToArray();         


        }

        public class Device
        {
            public List<DeviceBase> DeviceInfo{ get; set; }            
            public List<Warranty> WarrantyInfo { get; set; }
        }
        public class DeviceBase
        {
            public string Product { get; set; }
            public string OrderNumber { get; set; }
            public string ServiceTag { get; set; }
            public string ShipDate { get; set; }

        }
        public class Warranty
        {
            public string Service { get; set; }
            public string Provider { get; set; }
            public string StartDate { get; set; }
            public string EndDate { get; set; }
            public string TypeOfWarranty { get; set; }
        }

XML:

<GetAssetWarrantyResponse xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<GetAssetWarrantyResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://schemas.datacontract.org/2004/07/Dell.AWR.Domain.Asset">
<a:Faults/>
<a:Response>
<a:DellAsset>
<a:AssetParts i:nil="true"/>
<a:CountryLookupCode>11</a:CountryLookupCode>
<a:CustomerNumber>117731304</a:CustomerNumber>
<a:IsDuplicate>false</a:IsDuplicate>
<a:ItemClassCode>OC002</a:ItemClassCode>
<a:LocalChannel>66</a:LocalChannel>
<a:MachineDescription>COMPELLENT SC8000,1st,2nd,UPG</a:MachineDescription>
<a:OrderNumber>NANANANAN</a:OrderNumber>
<a:ParentServiceTag i:nil="true"/>
<a:ServiceTag>XXXXXXX</a:ServiceTag>
<a:ShipDate>2014-02-07T00:00:00</a:ShipDate>
<a:Warranties>
<a:Warranty>
<a:EndDate>2016-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>933-5366</a:ItemNumber>
<a:ServiceLevelCode>S9</a:ServiceLevelCode>
<a:ServiceLevelDescription>4 Hour On-Site Service</a:ServiceLevelDescription>
<a:ServiceLevelGroup>5</a:ServiceLevelGroup>
<a:ServiceProvider>UNY</a:ServiceProvider>
<a:StartDate>2015-07-31T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2016-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>974-9929</a:ItemNumber>
<a:ServiceLevelCode>ZL</a:ServiceLevelCode>
<a:ServiceLevelDescription>CML - Storage Center Core Base</a:ServiceLevelDescription>
<a:ServiceLevelGroup>11</a:ServiceLevelGroup>
<a:ServiceProvider>DELL</a:ServiceProvider>
<a:StartDate>2015-07-31T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2016-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>933-5406</a:ItemNumber>
<a:ServiceLevelCode>SV</a:ServiceLevelCode>
<a:ServiceLevelDescription>Silver Premium Support</a:ServiceLevelDescription>
<a:ServiceLevelGroup>8</a:ServiceLevelGroup>
<a:ServiceProvider>DELL</a:ServiceProvider>
<a:StartDate>2015-07-31T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2015-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>933-5416</a:ItemNumber>
<a:ServiceLevelCode>SV</a:ServiceLevelCode>
<a:ServiceLevelDescription>Silver Premium Support</a:ServiceLevelDescription>
<a:ServiceLevelGroup>8</a:ServiceLevelGroup>
<a:ServiceProvider>DELL</a:ServiceProvider>
<a:StartDate>2014-08-01T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2015-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>933-5376</a:ItemNumber>
<a:ServiceLevelCode>S9</a:ServiceLevelCode>
<a:ServiceLevelDescription>4 Hour On-Site Service</a:ServiceLevelDescription>
<a:ServiceLevelGroup>5</a:ServiceLevelGroup>
<a:ServiceProvider>UNY</a:ServiceProvider>
<a:StartDate>2014-08-01T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2015-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>975-0042</a:ItemNumber>
<a:ServiceLevelCode>ZL</a:ServiceLevelCode>
<a:ServiceLevelDescription>CML - Storage Center Core Base</a:ServiceLevelDescription>
<a:ServiceLevelGroup>11</a:ServiceLevelGroup>
<a:ServiceProvider>DELL</a:ServiceProvider>
<a:StartDate>2014-08-01T00:00:00</a:StartDate></a:Warranty>
<a:Warranty>
<a:EndDate>2014-07-31T23:59:59</a:EndDate>
<a:EntitlementType>EXTENDED</a:EntitlementType>
<a:ItemNumber>933-5376</a:ItemNumber>
<a:ServiceLevelCode>S9</a:ServiceLevelCode>
<a:ServiceLevelDescription>4 Hour On-Site Service</a:ServiceLevelDescription>
<a:ServiceLevelGroup>5</a:ServiceLevelGroup>
<a:ServiceProvider>UNY</a:ServiceProvider>
<a:StartDate>2014-02-07T00:00:00</a:StartDate></a:Warranty></a:Warranties></a:DellAsset></a:Response></GetAssetWarrantyResult></GetAssetWarrantyResponse>
jrider
  • 1,571
  • 1
  • 10
  • 26
  • Sorry I am a noob to calling this correctly. How would you suggest I correct this? Thank you for your patience – jrider Jan 15 '16 at 22:08
  • I suggest you edit your question to explain what you actually want to do. Now that you have fixed your typo, your list `xlAsset` is fully populated. So, what's the problem? – dbc Jan 15 '16 at 22:11
  • I edited the question. It should be now that I have set these variables into the class, how would I call the class correctly to display the values or get the count of the List<>? – jrider Jan 15 '16 at 22:13
  • You mean you want to do `var testDevice = xlAsset.FirstOrDefault();` ? See [`Enumerable.FirstOrDefault Method (IEnumerable)`](https://msdn.microsoft.com/library/bb340482.aspx). – dbc Jan 15 '16 at 22:23
  • I see what I did wrong. I am going about this the wrong way. This is what I am looking for: http://stackoverflow.com/questions/8196117/c-sharp-get-and-set-properties-for-a-list-collection. Thanks for your help – jrider Jan 15 '16 at 22:32

1 Answers1

1

The issue was with the class being created correctly. Here is the correction for anyone that is curious:

public class Device
        {
            private List<DeviceBase> _deviceInfo = new List<DeviceBase>();
            private List<Warranty> _warrantyInfo = new List<Warranty>();

            public List<DeviceBase> DeviceInfo
            {
                get
                { return _deviceInfo; }
                set
                { _deviceInfo = value; }
            }            
            public List<Warranty> WarrantyInfo
            {
                get
                { return _warrantyInfo; }
                set
                { _warrantyInfo = value; }
            }
        }

        public class DeviceBase
        {
            public string Product { get; set; }
            public string OrderNumber { get; set; }
            public string ServiceTag { get; set; }
            public string ShipDate { get; set; }

        }
        public class Warranty
        {
            public string Service { get; set; }
            public string Provider { get; set; }
            public string StartDate { get; set; }
            public string EndDate { get; set; }
            public string TypeOfWarranty { get; set; }
        }
jrider
  • 1,571
  • 1
  • 10
  • 26