Results 1 to 3 of 3

Thread: Problem when returning custom object by webservice

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Problem when returning custom object by webservice

    Im trying to return a collection of objects, the collection object itself inherits from CollectionBase. And somehow the objects need to be serializable...

    When Im trying to run the webservice I get this error :

    You must implement a default accessor on EasyPrinting.EasyPrinting.CDocumentCollection because it inherits from ICollection.


    How can I implement such a default accessor?


    kind regards
    Henrik

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Check out "default keyword" on MSDN for full info on this.

    But in the meantime, I wrote a default accessor for one of my classes recently...

    VB Code:
    1. <Serializable()> Public Class BoundaryDataStorage
    2. '...
    3. Default Public Property Boundary(ByVal index As Integer) As Boundary
    4.     Get
    5.         '...
    6.     End Get
    7.     Set(ByVal Value As Boundary)
    8.         '...
    9.     End Set
    10. End Property
    11. '...
    12. End Class

    Basically it lets the class behave like a wrapper for an array, returning some internal data as pertains to a passed in parameter.

    So you can call the above sub with either of the following to get the same result...

    VB Code:
    1. dim x as boundary
    2. x = MyBoundaryDataStorageObject.Boundary(i)
    or
    VB Code:
    1. dim x as boundary
    2. x = MyBoundaryDataStorageObject(i)
    Last edited by wossname; May 26th, 2004 at 09:14 AM.
    I don't live here any more.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Yeah, I reminded mysself about that keyword minutes after I posted the question...

    Anyway, I put a default accessor... and something strange happened...

    I have a webmethod that returns a collection of CDocument objects, a CDocumentCollection object... But when I run this method as a webmethod instead it is created in the proxy class as


    CDocument()

    My method that is using this can't use this, it works with CDocumentCollection only... not an array of CDocument objects.

    Here is my webmethod
    VB Code:
    1. <WebMethod()> Public Function CreatePrintList(ByVal OrderNo As String, ByVal OpNo As Integer, ByVal PartNo As String) As CDocumentCollection

    And here is the proxy class that was generated:

    VB Code:
    1. Public Function CreatePrintList(ByVal OrderNo As String, ByVal OpNo As Integer, ByVal PartNo As String) As CDocument()
    2.             Dim results() As Object = Me.Invoke("CreatePrintList", New Object() {OrderNo, OpNo, PartNo})
    3.             Return CType(results(0),CDocument())
    4.         End Function


    Why did this conversion take place???

    kind regards
    Henrik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width