0

我有一个 WSDL 文档,它有上面这样的元素。

  <s:element name="NewPortalOrder">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="OrderType" type="tns:CardSalesType" />
        <s:element minOccurs="1" maxOccurs="1" name="Customer" type="tns:PortalCustomerContainer" />
        <s:element minOccurs="1" maxOccurs="1" name="InvoiceAddress" type="tns:AddressContainer" />
        <s:element minOccurs="1" maxOccurs="1" name="DeliveryAddress" type="tns:AddressContainer" />
        <s:element minOccurs="0" maxOccurs="1" name="Cards" type="tns:ArrayOfPortalCardContainer" />
      </s:sequence>
    </s:complexType>
  </s:element>

我将 WSDL 文件作为 ServiceReference 添加到解决方案中。

在服务器端

  WS.NewPortalOrderRequest order = new WS.NewPortalOrderRequest();

  order.InvoiceAddress.AddressLine1 = txtAddress.Text;
  order.InvoiceAddress.AddressLine2 = txtAddress2.Text;

在线order.InvoiceAddress.AddressLine1 = txtAddress.Text;我得到Object reference not set to an instance of an object.错误。

当我看的时候order.InvoiceAddress,我发现那是空的。为什么我会收到此错误?我该如何解决?

4

1 回答 1

3

很可能您需要在 中创建一个实例InvoiceAddressNewPortalOrderRequest如下所示:

WS.NewPortalOrderRequest order = new WS.NewPortalOrderRequest();

order.InvoiceAddress = new WS.InvoiceAddress();

// Now you can assign values to InvoiceAddress' property:
order.InvoiceAddress.AddressLine1 = txtAddress.Text;
order.InvoiceAddress.AddressLine2 = txtAddress2.Text;

您可能需要order.InvoiceAddress = new WS.AddressContainer()根据 WSDL 进行操作,但我对此不是 100% 确定的。

于 2013-04-30T08:14:07.680 回答