我有一个包含OrderInformation_type
类的WSDL,该类包含三个私有属性,这些属性本身就是类:Header_type
,PromotionInformation_type
和ItemInformation_type[]
数组。我已将OrderInformation_type
的对象初始化为' order'。此外,我已初始化order.Header_type
标题和order.PromotionInformation_type
对象,这些对象已成功初始化,并且可以轻松设置其属性。但是当我尝试初始化order.ItemInformation_type[]
对象时,我在运行时声明错误,对象引用没有设置为object.Considering
的实例,OrderInformation_type
有ItemInformation_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是获得错误的行。
答案 0 :(得分:1)
orderinfo.ItemInformation是一个数组。您正尝试将尚未创建的内容分配给[0]。添加
orderinfo.ItemInformation = new new ServiceReference1.PromotionInformation_type [];
应该这样做......