Submitting an Array to a Webservice.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: MMesich (MMesich_at_discussions.microsoft.com)
Date: 10/06/04


Date: Tue, 5 Oct 2004 17:28:18 -0700

I've got an order entry webservice whose WSDL looks like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <OrderSubmit xmlns="http://tempuri.org/WebServices/beta">
      <varCustNum>string</varCustNum>
      <varPassword>string</varPassword>
      <Order>
        <Terms>string</Terms>
        <ShipContact />
        <ShipAddress1>string</ShipAddress1>
        <ShipAddress2>string</ShipAddress2>
        <ShipCity>string</ShipCity>
        <ShipZip>string</ShipZip>
        <ShipState>string</ShipState>
        <Items>
          <Item>
            <sku>string</sku>
            <qty>string</qty>
            <location>string</location>
            <shipvia>string</shipvia>
          </Item>
          <Item>
            <sku>string</sku>
            <qty>string</qty>
            <location>string</location>
            <shipvia>string</shipvia>
          </Item>
        </Items>
      </Order>
    </OrderSubmit>
  </soap:Body>
</soap:Envelope>

This WSDL is auto-generated from these class definitions:

Public Class OrderResult
        Public ErrorMessage As String
        Public Status As String
    End Class

    Public Class Order
        ' *** Reseller Info ***
        Public Terms As String
        ' *** Customer Shipping Information ***
        Public ShipContact as string
        Public ShipAddress1 As String
        Public ShipAddress2 As String
        Public ShipCity As String
        Public ShipZip As String
        Public ShipState As String
        '*** Detailed Item Array ***
        Public Items As Item()
    End Class

    Public Class Item
        Public sku As String
        Public qty As Integer
        Public location As String
        Public shipvia As String
    End Class

So my problem is how do I fill the array of Items? I must be missing some
funky Array parameter or something. I try this from a client ASPX file:

        Dim varOrder As New WS.Order '** Instantiate Webservice Object

        varOrder.CustomerNumber = "340000v"
        varOrder.Password = "pass1"
        varOrder.Terms = "N30"
        varOrder.ShipAddress1 = "123 Anystreet"
        varOrder.ShipAddress2 = "Suite ABC"
        varOrder.ShipCity = "Anytown"
        varOrder.ShipState = "GA"
        varOrder.ShipZip = "55555"
        varOrder.ShipContact = "Abe Aberman"

        ' *** Problem comes here ***
        varOrder.Items(0).sku = "SKU1"
        varOrder.Items(0).qty = 5
        varOrder.Items(0).location = "ATL"
        varOrder.Items(0).shipvia = "UPS"

Intellisense supports the code above just fine. But when executed I get:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 59:
Line 60: 'Dim tstItems As Items
Line 61: varOrder.Items(0).sku = "SKU1" <<---- Highlighted line
Line 62: varOrder.Items(0).qty = 5
Line 63: varOrder.Items(0).location = "ATL"
 

[NullReferenceException: Object reference not set to an instance of an
object.]
   OrderEntryTestPage.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\OrderEntryTestPage\WebForm1.aspx.vb:61
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

 
I've tried working with creating an array locally and then setting the
webservice array equal to it but I'm having a heck of a time even with that.
Anyone out there have experience with Class Arrays and what I'm missing to
get it submissible to my little webservice?

Thanks in advance!

  ~ Michael ~



Relevant Pages

  • Re: complex types in a Web service
    ... I understand that the WSDL specifies the complex types for interop purposes, ... having it return an array of Patients types isn't what ... This is a bit hard since the client webservice proxy generate the types ... I think this is likely caused by the custom collection class you used only ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • How do you store a stoopid array in the stoopid ViewState?
    ... Object reference not set to an instance of an object. ... An unhandled exception occurred during the execution of the ... Is there any way to create an immediate array in C#? ... public void Page_Init (object sender, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: complex types in a Web service
    ... This is a bit hard since the client webservice proxy generate the types ... according to the webservice's WSDL document. ... WSDL will always use SOAP Array to represent ... I think this is likely caused by the custom collection class you used only ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: ArrayList as parameter to WebService
    ... Guys - thank you for your replies: I have tried changing the webservice ... parameter to an array of object, and also to an array of the specific class ... > Best regards, ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem instantiating an array of objects or array of class instances
    ... unfamiliarity on how class instances are instantiated in an array. ... NodeTreeMgr mySingleNodeTreeMgr = new NodeTreeMgr; ... Unhandled Exception: System.NullReferenceException: Object reference ... Node returnNode = new Node; ...
    (microsoft.public.dotnet.languages.csharp)