根据 WSDL 初始化 Soap 请求的项目时,对象引用未设置为对象的实例
Object reference not set to an instance of an object while initializing items for a Soap request as per the WSDL
我有一个包含 OrderInformation_type
class 的 WSDL,由三个私有属性组成,这些属性本身是 class:Header_type
、PromotionInformation_type
和一个数组分别为 ItemInformation_type[]
。我已经将 OrderInformation_type
的对象初始化为 'order'。此外,我已经初始化了成功初始化的 order.Header_type
header 和 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;
粗体是出现错误的行。
orderinfo.ItemInformation 是一个数组。您正在尝试将 [0] 分配给尚未创建的内容。添加
orderinfo.ItemInformation = new new
ServiceReference1.PromotionInformation_type[];
应该做...
我有一个包含 OrderInformation_type
class 的 WSDL,由三个私有属性组成,这些属性本身是 class:Header_type
、PromotionInformation_type
和一个数组分别为 ItemInformation_type[]
。我已经将 OrderInformation_type
的对象初始化为 'order'。此外,我已经初始化了成功初始化的 order.Header_type
header 和 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;
粗体是出现错误的行。
orderinfo.ItemInformation 是一个数组。您正在尝试将 [0] 分配给尚未创建的内容。添加
orderinfo.ItemInformation = new new ServiceReference1.PromotionInformation_type[];
应该做...