在根据WSDL初始化Soap请求的项时,对象引用未设置为对象的实例

时间:2018-05-26 22:38:02

标签: c# .net wsdl

我有一个包含OrderInformation_type类的WSDL,该类包含三个私有属性,这些属性本身就是类:Header_typePromotionInformation_typeItemInformation_type[]数组。我已将OrderInformation_type的对象初始化为' order'。此外,我已初始化order.Header_type标题和order.PromotionInformation_type对象,这些对象已成功初始化,并且可以轻松设置其属性。但是当我尝试初始化order.ItemInformation_type[]对象时,我在运行时声明错误,对象引用没有设置为object.Considering的实例,OrderInformation_typeItemInformation_type属性为数组,因此我按以下方式初始化它:

WindowsFormsApplication1.ServiceReference1.OrderInformation_type orderinfo = new ServiceReference1.OrderInformation_type();
            orderinfo.Header = new ServiceReference1.Header_type();
            orderinfo.Header.AccountNumber = 496570;
            orderinfo.Header.DistributorIdentifier = ServiceReference1.Header_typeDistributorIdentifier.MBA;

            orderinfo.PromotionInformation = new ServiceReference1.PromotionInformation_type();
            **orderinfo.ItemInformation[0] = new ServiceReference1.ItemInformation_type();**
            orderinfo.ItemInformation[0].ItemID = "95847";
            orderinfo.ItemInformation[0].ItemIDType = ServiceReference1.ItemInformation_typeItemIDType.D;
            orderinfo.ItemInformation[0].Quantity = 1;

Bold one是获得错误的行。

1 个答案:

答案 0 :(得分:1)

orderinfo.ItemInformation是一个数组。您正尝试将尚未创建的内容分配给[0]。添加

  

orderinfo.ItemInformation = new new   ServiceReference1.PromotionInformation_type [];

应该这样做......