Soap Request containing an array?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • craig

    #1

    Soap Request containing an array?


    I'm fried on this problem...It's vb.net, dealing with a web service
    that requires input as an array of a particular data structure and I
    can't get the code to compile or run...

    Basically, the webservice is showing me the following:
    Public structure A
    public a1 as string
    end structure

    Public structure B
    public b1 as string
    public b2 as string
    end structure

    Public structure RequestStructur e
    public PartA as A
    public PartB() as B
    end structure

    Public structure ResponseStructu re
    public ok as string
    end structure

    <webrequest()Pu blic Function DoStuff(byval RequestStructur e as
    RequestStructur e) as ResponseStructu re


    So, I have the following code:
    dim myA as new com.xxx.xxx.xxx .etc.A
    myA.a1="Test"
    dim myRequestStruct ure as new com.xxx.xxx.xxx .etc.RequestStr ucture
    myRequestStruct ure.PartA=myA
    (so far, so good)

    dim myB(10) as new com.xxx.xxx.xxx .etc.B
    results in a syntax error "Arrays cannot be declared with new". Ok, so
    I'll take out "new". It compiles, but, I then get an "object reference
    not set to an instance of an object" error later on when I attempt to
    put data into myB.

    So, I changed the dim to:
    dim myB as arraylist
    and then, each time I put something in, I put it in as a structure in
    the form of structure B.

    But, that creates a problem when I get to the actual web service call,
    since I cannot say:
    MyRequestStruct ure.PartB=MyB
    because MyB is an arraylist, not of type B. There probably is a way to
    make this work, by pulling out the individual items in the arraylist,
    but I've tried several dozen seemingly clever ways to assign the data
    to MyRequestStruct ure.PartB and it either doesn't pass syntactically,
    or it blows up with an "object reference..." error.

    So, I figured I'd create my own, local, structure containing the B
    structure from the webservice. That doesn't work, since I can't assign
    my local structure to myRequestStruct ure.PartB because they are
    technically 2 different types.

    So, I figured I'd create a local structure containing the B structure
    inside it. That's basically the same as the ArrayList solution, and
    has the same problems.

    I thought "createinstance " would be the solution, but I haven't had
    any success in getting that to work with a structure defined in a web
    service.

    I've looked all over the place trying to find ANY example of anyone
    ever passing a structure and have found NONE. Surely, someone has done
    this without brute-force coding it as discrete xml instead of a soap
    call...

    And, I have NO control over the webservice at the other end.

    Craig


  • Andrew Brook

    #2
    Re: Soap Request containing an array?

    Hi Craig,

    It looks like the only problem you have is creating an array of structure
    B... would something like the following work?

    Dim strucA as new structureA
    strucA.a1 = "structureA "

    'Create an empty array of structureB's
    Dim strucArrB(1) as structureB

    'set first element in the array
    strArrB(0) = new structureB
    strArrB(0).b1 = "test"
    strArrB(0).b2 = "test"

    'set the second element in the array
    strArrB(1) = new structureB
    strArrB(1).b1 = "test"
    strArrB(1).b2 = "test"

    Dim req as new RequestStructur e
    req.PartA = strucA
    req.PartB = strArrB

    etc..

    Andrew


    "craig" <craig@vandenpl as.comwrote in message
    news:cjt4d29kcb 82jtqg23k0k153u lerbjfbd5@4ax.c om...
    >
    I'm fried on this problem...It's vb.net, dealing with a web service
    that requires input as an array of a particular data structure and I
    can't get the code to compile or run...
    >
    Basically, the webservice is showing me the following:
    Public structure A
    public a1 as string
    end structure
    >
    Public structure B
    public b1 as string
    public b2 as string
    end structure
    >
    Public structure RequestStructur e
    public PartA as A
    public PartB() as B
    end structure
    >
    Public structure ResponseStructu re
    public ok as string
    end structure
    >
    <webrequest()Pu blic Function DoStuff(byval RequestStructur e as
    RequestStructur e) as ResponseStructu re
    >
    >
    So, I have the following code:
    dim myA as new com.xxx.xxx.xxx .etc.A
    myA.a1="Test"
    dim myRequestStruct ure as new com.xxx.xxx.xxx .etc.RequestStr ucture
    myRequestStruct ure.PartA=myA
    (so far, so good)
    >
    dim myB(10) as new com.xxx.xxx.xxx .etc.B
    results in a syntax error "Arrays cannot be declared with new". Ok, so
    I'll take out "new". It compiles, but, I then get an "object reference
    not set to an instance of an object" error later on when I attempt to
    put data into myB.
    >
    So, I changed the dim to:
    dim myB as arraylist
    and then, each time I put something in, I put it in as a structure in
    the form of structure B.
    >
    But, that creates a problem when I get to the actual web service call,
    since I cannot say:
    MyRequestStruct ure.PartB=MyB
    because MyB is an arraylist, not of type B. There probably is a way to
    make this work, by pulling out the individual items in the arraylist,
    but I've tried several dozen seemingly clever ways to assign the data
    to MyRequestStruct ure.PartB and it either doesn't pass syntactically,
    or it blows up with an "object reference..." error.
    >
    So, I figured I'd create my own, local, structure containing the B
    structure from the webservice. That doesn't work, since I can't assign
    my local structure to myRequestStruct ure.PartB because they are
    technically 2 different types.
    >
    So, I figured I'd create a local structure containing the B structure
    inside it. That's basically the same as the ArrayList solution, and
    has the same problems.
    >
    I thought "createinstance " would be the solution, but I haven't had
    any success in getting that to work with a structure defined in a web
    service.
    >
    I've looked all over the place trying to find ANY example of anyone
    ever passing a structure and have found NONE. Surely, someone has done
    this without brute-force coding it as discrete xml instead of a soap
    call...
    >
    And, I have NO control over the webservice at the other end.
    >
    Craig
    >
    >

    Comment

    • craig

      #3
      Re: Soap Request containing an array?


      No, that actually doesn't work. The reason being that structure B is a
      derived structure from a web service.

      I *did* find the solution, however.

      Define a new class, for example:
      Class MyNewClass
      public shared MyBStructre(100 ) as com.xxxx.xxxx.x xxx.B
      end Class

      Then, in the actual code, you can do the following:
      dim MyLocalB as new MyNewClass.MyBS tructure

      Craig



      On Mon, 7 Aug 2006 11:46:37 +0100, "Andrew Brook" <ykoorb@hotmail .com>
      wrote:
      >Hi Craig,
      >
      >It looks like the only problem you have is creating an array of structure
      >B... would something like the following work?
      >
      >Dim strucA as new structureA
      >strucA.a1 = "structureA "
      >
      >'Create an empty array of structureB's
      >Dim strucArrB(1) as structureB
      >
      >'set first element in the array
      >strArrB(0) = new structureB
      >strArrB(0).b 1 = "test"
      >strArrB(0).b 2 = "test"
      >
      >'set the second element in the array
      >strArrB(1) = new structureB
      >strArrB(1).b 1 = "test"
      >strArrB(1).b 2 = "test"
      >
      >Dim req as new RequestStructur e
      >req.PartA = strucA
      >req.PartB = strArrB
      >
      >etc..
      >
      >Andrew
      >
      >
      >"craig" <craig@vandenpl as.comwrote in message
      >news:cjt4d29kc b82jtqg23k0k153 ulerbjfbd5@4ax. com...
      >>
      >I'm fried on this problem...It's vb.net, dealing with a web service
      >that requires input as an array of a particular data structure and I
      >can't get the code to compile or run...
      >>
      >Basically, the webservice is showing me the following:
      >Public structure A
      > public a1 as string
      >end structure
      >>
      >Public structure B
      > public b1 as string
      > public b2 as string
      >end structure
      >>
      >Public structure RequestStructur e
      > public PartA as A
      > public PartB() as B
      >end structure
      >>
      >Public structure ResponseStructu re
      > public ok as string
      >end structure
      >>
      ><webrequest()P ublic Function DoStuff(byval RequestStructur e as
      >RequestStructu re) as ResponseStructu re
      >>
      >>
      >So, I have the following code:
      >dim myA as new com.xxx.xxx.xxx .etc.A
      >myA.a1="Test "
      >dim myRequestStruct ure as new com.xxx.xxx.xxx .etc.RequestStr ucture
      >myRequestStruc ture.PartA=myA
      >(so far, so good)
      >>
      >dim myB(10) as new com.xxx.xxx.xxx .etc.B
      >results in a syntax error "Arrays cannot be declared with new". Ok, so
      >I'll take out "new". It compiles, but, I then get an "object reference
      >not set to an instance of an object" error later on when I attempt to
      >put data into myB.
      >>
      >So, I changed the dim to:
      >dim myB as arraylist
      >and then, each time I put something in, I put it in as a structure in
      >the form of structure B.
      >>
      >But, that creates a problem when I get to the actual web service call,
      >since I cannot say:
      >MyRequestStruc ture.PartB=MyB
      >because MyB is an arraylist, not of type B. There probably is a way to
      >make this work, by pulling out the individual items in the arraylist,
      >but I've tried several dozen seemingly clever ways to assign the data
      >to MyRequestStruct ure.PartB and it either doesn't pass syntactically,
      >or it blows up with an "object reference..." error.
      >>
      >So, I figured I'd create my own, local, structure containing the B
      >structure from the webservice. That doesn't work, since I can't assign
      >my local structure to myRequestStruct ure.PartB because they are
      >technically 2 different types.
      >>
      >So, I figured I'd create a local structure containing the B structure
      >inside it. That's basically the same as the ArrayList solution, and
      >has the same problems.
      >>
      >I thought "createinstance " would be the solution, but I haven't had
      >any success in getting that to work with a structure defined in a web
      >service.
      >>
      >I've looked all over the place trying to find ANY example of anyone
      >ever passing a structure and have found NONE. Surely, someone has done
      >this without brute-force coding it as discrete xml instead of a soap
      >call...
      >>
      >And, I have NO control over the webservice at the other end.
      >>
      >Craig
      >>
      >>
      >

      Comment

      Working...