Asynchronous communication and IDictionary....

Discussion in 'ASP .Net Web Services' started by Robin Mark Tucker, May 25, 2006.

  1. Hi,


    Please forgive me I'm completely new to ASP.NET, having just setup a service
    yesterday for testing/playing around at work. I have a fat client at the
    moment that contains an abstract DataConnection class. Derived from that I
    have SQLServerDataConnection, OracleDataConnection, MySQLDataConnection,
    etc. I'm hoping to add ASPNETDataConnection to the list of connections the
    factory can return, but I've got a few questions about how best to implement
    this.

    Firstly, I can't use many of the classes I implement and manipulate in my
    disconnected cache. It seems ASPNET doesn't like serializing IDictionary
    for instance. I suppose I can get around this by creating my own "proxy"
    class, that takes the data in some other format and creates the various
    required collections, but perhaps there is a way of giving a class suitable
    attributes to enable ASPNET to receive and return these types in it's own
    generated code?

    As an example, I have an enumeration called "ConditionEnum":


    Public Enum ConditionEnum

    Green
    Yellow
    Red
    Undefined

    End Enum


    I then have another class that hashes an integer key (a record primary key
    in the database) to a given Condition:


    Public Class ConditionsHash

    Inherits Dictionary (Of Integer, ConditionEnum)

    ...
    End Class


    One of the methods on my data connection class returns a ConditionsHash
    object:


    Public Function GetConditions (ByRef theConditionsHash As ConditionsHash) As
    DataError

    ...
    ...
    Return theConditionsHash

    End Function


    Now it appears my project fails to generate a proxy for ConditionsHash
    because it derives from IDictionary. What is the preferred solution in this
    case?



    Secondly, if I kick off an operation that might take some time (say,
    processing 1,000 records in a database), how do I notify the client of my
    progress? I don't want the service to be too chatty, so I don't want to
    have to send 1,000 requests when I can send 1 collection of keys to process
    in 1 request. Is it a question of the client executing another method on
    the service ("GetItemsCompleted() As Integer")? Are calls like this queued
    and executed in turn? ie. will ASPNET finish the method call that processes
    the records and then execute GetItemsCompleted? Alternatively, is there a
    callback mechanism available to enable the service class to fire a
    "ItemCompleted" event on the proxy after each of it's iterations, ie.:

    <WebMethod()>_
    Public Sub ExecuteBatch (ByVal theIntegers As ArrayList)


    For i as Integer = 0 To theIntegers.Count - 1


    ' Perform some random action....

    DoSomethingWithTheInteger (i)



    ' Raise completed event to the client for every 10 we process.

    If (i Mod 10) = 0 Then
    RaiseEvent Progress ( i )
    End if


    Next

    End Sub



    Thanks for your insights.
    Robin Mark Tucker, May 25, 2006
    #1
    1. Advertising

  2. Okay, I found out how to pass IDictionary into and out of a web service.
    As this chap points out, you simply need helper classes to flatten your
    structures into arrays: http://www.markrichman.com/Collections.pdf.

    "Robin Mark Tucker" <> wrote in
    message news:e540ej$5ob$1$...
    > Hi,
    >
    >
    > Please forgive me I'm completely new to ASP.NET, having just setup a
    > service yesterday for testing/playing around at work. I have a fat client
    > at the moment that contains an abstract DataConnection class. Derived
    > from that I have SQLServerDataConnection, OracleDataConnection,
    > MySQLDataConnection, etc. I'm hoping to add ASPNETDataConnection to the
    > list of connections the factory can return, but I've got a few questions
    > about how best to implement this.
    >
    > Firstly, I can't use many of the classes I implement and manipulate in my
    > disconnected cache. It seems ASPNET doesn't like serializing IDictionary
    > for instance. I suppose I can get around this by creating my own "proxy"
    > class, that takes the data in some other format and creates the various
    > required collections, but perhaps there is a way of giving a class
    > suitable attributes to enable ASPNET to receive and return these types in
    > it's own generated code?
    >
    > As an example, I have an enumeration called "ConditionEnum":
    >
    >
    > Public Enum ConditionEnum
    >
    > Green
    > Yellow
    > Red
    > Undefined
    >
    > End Enum
    >
    >
    > I then have another class that hashes an integer key (a record primary key
    > in the database) to a given Condition:
    >
    >
    > Public Class ConditionsHash
    >
    > Inherits Dictionary (Of Integer, ConditionEnum)
    >
    > ...
    > End Class
    >
    >
    > One of the methods on my data connection class returns a ConditionsHash
    > object:
    >
    >
    > Public Function GetConditions (ByRef theConditionsHash As ConditionsHash)
    > As DataError
    >
    > ...
    > ...
    > Return theConditionsHash
    >
    > End Function
    >
    >
    > Now it appears my project fails to generate a proxy for ConditionsHash
    > because it derives from IDictionary. What is the preferred solution in
    > this case?
    >
    >
    >
    > Secondly, if I kick off an operation that might take some time (say,
    > processing 1,000 records in a database), how do I notify the client of my
    > progress? I don't want the service to be too chatty, so I don't want to
    > have to send 1,000 requests when I can send 1 collection of keys to
    > process in 1 request. Is it a question of the client executing another
    > method on the service ("GetItemsCompleted() As Integer")? Are calls like
    > this queued and executed in turn? ie. will ASPNET finish the method call
    > that processes the records and then execute GetItemsCompleted?
    > Alternatively, is there a callback mechanism available to enable the
    > service class to fire a "ItemCompleted" event on the proxy after each of
    > it's iterations, ie.:
    >
    > <WebMethod()>_
    > Public Sub ExecuteBatch (ByVal theIntegers As ArrayList)
    >
    >
    > For i as Integer = 0 To theIntegers.Count - 1
    >
    >
    > ' Perform some random action....
    >
    > DoSomethingWithTheInteger (i)
    >
    >
    >
    > ' Raise completed event to the client for every 10 we process.
    >
    > If (i Mod 10) = 0 Then
    > RaiseEvent Progress ( i )
    > End if
    >
    >
    > Next
    >
    > End Sub
    >
    >
    >
    > Thanks for your insights.
    >
    >
    >
    Robin Mark Tucker, May 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Trevor
    Replies:
    6
    Views:
    3,567
    sahar
    Nov 5, 2010
  2. Adam Manek

    JUnit - asynchronous communication

    Adam Manek, Dec 12, 2004, in forum: Java
    Replies:
    0
    Views:
    642
    Adam Manek
    Dec 12, 2004
  3. SushiSean

    How to map IDictionary to repeater?

    SushiSean, Jan 2, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    980
  4. D Browne

    Invalid cast with IDictionary

    D Browne, Jun 3, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    310
    D Browne
    Jun 4, 2008
  5. iScout
    Replies:
    0
    Views:
    157
    iScout
    Mar 23, 2006
Loading...

Share This Page