Passing arrays from Classic ASP to .NET components - How do you do this transparently?

Discussion in 'ASP .Net' started by Mark, Dec 4, 2003.

  1. Mark

    Mark Guest

    Hi

    From what I understand, you can pass arrays from classic ASP to .NET using
    interop, but you have to change the type of the.NET parameter to object.
    This seems to be because classic ASP passes a variant containing an array,
    and interop expects a parameter of type object if you are passing a variant
    (you are expected to cast it to the correct type in your code). I'd like to
    find a way of passing arrays so that you don't need to change the types of
    all arrays to object in method signatures - since this throws away compile
    time type checking.

    Has anyone got any ideas as to how we could do this? (Unless you use a type
    library, ASP queries the CCW for type information - although what is
    returned can be changed by overriding the correct method(s) in the object's
    IReflect interface).

    We have come up with a number of ideas which include writing a wrapper class
    which customises IDispatch by overriding IReflect, but does anyone have a
    simpler solution? Are there any commercial components which can solve this
    problem? We also considering using web services but I don't think that we
    would get the same OO semantics using this approach, would we? We could
    write a simple .NET wrapper class for each .NET class or we could add extra
    methods to the original class in order to solve this problem. Writing a
    wrapper object in COM has also been considered, as has passing the data as a
    string (which would not be very transparent, it would be inefficient). We
    also considered writing our own collection classes which we would us instead
    of arrays, but it might be difficult to make this transparent.

    Any ideas would be really appreciated..

    Thanks

    Mark
     
    Mark, Dec 4, 2003
    #1
    1. Advertising

  2. I'm afraid you're way off. ASP and ASP.Net are 2 different technologies.
    There is no interop that you can use to communicate between the 2. They live
    in different application domains; different processes, different memory
    spaces. The only way an ASP app can talk to an ASP.Net app (or vice versa)
    is via HTTP. That is, you can send an HTTP request from one to the other,
    passing data in the form of Query String or Form Post. Well, you could have
    one write to a file or database as well, and have the other read it.

    Interop is used for DLLs, COM objects, Windows API calls, etc.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Mark" <> wrote in message
    news:...
    > Hi
    >
    > From what I understand, you can pass arrays from classic ASP to .NET using
    > interop, but you have to change the type of the.NET parameter to object.
    > This seems to be because classic ASP passes a variant containing an array,
    > and interop expects a parameter of type object if you are passing a

    variant
    > (you are expected to cast it to the correct type in your code). I'd like

    to
    > find a way of passing arrays so that you don't need to change the types of
    > all arrays to object in method signatures - since this throws away compile
    > time type checking.
    >
    > Has anyone got any ideas as to how we could do this? (Unless you use a

    type
    > library, ASP queries the CCW for type information - although what is
    > returned can be changed by overriding the correct method(s) in the

    object's
    > IReflect interface).
    >
    > We have come up with a number of ideas which include writing a wrapper

    class
    > which customises IDispatch by overriding IReflect, but does anyone have a
    > simpler solution? Are there any commercial components which can solve this
    > problem? We also considering using web services but I don't think that we
    > would get the same OO semantics using this approach, would we? We could
    > write a simple .NET wrapper class for each .NET class or we could add

    extra
    > methods to the original class in order to solve this problem. Writing a
    > wrapper object in COM has also been considered, as has passing the data as

    a
    > string (which would not be very transparent, it would be inefficient). We
    > also considered writing our own collection classes which we would us

    instead
    > of arrays, but it might be difficult to make this transparent.
    >
    > Any ideas would be really appreciated..
    >
    > Thanks
    >
    > Mark
    >
    >
     
    Kevin Spencer, Dec 4, 2003
    #2
    1. Advertising

  3. I haven't tried it, but I'm pretty sure you can write a Class Library in
    ..NET, register it as a COM object, and call it from ASP.

    If VB6 can call a .NET library, I see no reason why ASP couldn't either.

    --Matthew W. Jackson

    "Kevin Spencer" <> wrote in message
    news:...
    > I'm afraid you're way off. ASP and ASP.Net are 2 different technologies.
    > There is no interop that you can use to communicate between the 2. They

    live
    > in different application domains; different processes, different memory
    > spaces. The only way an ASP app can talk to an ASP.Net app (or vice versa)
    > is via HTTP. That is, you can send an HTTP request from one to the other,
    > passing data in the form of Query String or Form Post. Well, you could

    have
    > one write to a file or database as well, and have the other read it.
    >
    > Interop is used for DLLs, COM objects, Windows API calls, etc.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Mark" <> wrote in message
    > news:...
    > > Hi
    > >
    > > From what I understand, you can pass arrays from classic ASP to .NET

    using
    > > interop, but you have to change the type of the.NET parameter to object.
    > > This seems to be because classic ASP passes a variant containing an

    array,
    > > and interop expects a parameter of type object if you are passing a

    > variant
    > > (you are expected to cast it to the correct type in your code). I'd like

    > to
    > > find a way of passing arrays so that you don't need to change the types

    of
    > > all arrays to object in method signatures - since this throws away

    compile
    > > time type checking.
    > >
    > > Has anyone got any ideas as to how we could do this? (Unless you use a

    > type
    > > library, ASP queries the CCW for type information - although what is
    > > returned can be changed by overriding the correct method(s) in the

    > object's
    > > IReflect interface).
    > >
    > > We have come up with a number of ideas which include writing a wrapper

    > class
    > > which customises IDispatch by overriding IReflect, but does anyone have

    a
    > > simpler solution? Are there any commercial components which can solve

    this
    > > problem? We also considering using web services but I don't think that

    we
    > > would get the same OO semantics using this approach, would we? We could
    > > write a simple .NET wrapper class for each .NET class or we could add

    > extra
    > > methods to the original class in order to solve this problem. Writing a
    > > wrapper object in COM has also been considered, as has passing the data

    as
    > a
    > > string (which would not be very transparent, it would be inefficient).

    We
    > > also considered writing our own collection classes which we would us

    > instead
    > > of arrays, but it might be difficult to make this transparent.
    > >
    > > Any ideas would be really appreciated..
    > >
    > > Thanks
    > >
    > > Mark
    > >
    > >

    >
    >
     
    Matthew W. Jackson, Dec 5, 2003
    #3
  4. Hi.

    As I read you mail, what you want to do is call a compont written in .NET
    from an ASP page?

    First of all, your .NET component would have to be registered as a COM
    component. That's quite easy if you're familiar with COM.

    Regarding how to write the interface for your class so that ASP can
    understand the class, you might be able to define your method like this
    void method( object[] args )
    but you surely can't do this
    void method( int[] args )

    The reason is that, as you wrote, ASP passes a variant containing an array.
    But to be more specific, ASP can only operate on arrays, if they are arrays
    of variants. It can't handle arrays of ints, strings or any other type.
    This can only be handled by passing an array of variants where each variant
    actually contains an int or a string.

    Other COM aware languages, e.g. VB6 or C++, don't have any problems
    operating on arrays of integers or strings, but ASP ( or VBScript to be
    precise ) can't.

    If you decide to go down the path of creating a .NET component to be used by
    ASP, I suggest that you create a wrapper class that converts data as needed
    and then call the sspecific strongly typed method on the real component

    Pete

    "Mark" <> wrote in message
    news:...
    > Hi
    >
    > From what I understand, you can pass arrays from classic ASP to .NET using
    > interop, but you have to change the type of the.NET parameter to object.
    > This seems to be because classic ASP passes a variant containing an array,
    > and interop expects a parameter of type object if you are passing a

    variant
    > (you are expected to cast it to the correct type in your code). I'd like

    to
    > find a way of passing arrays so that you don't need to change the types of
    > all arrays to object in method signatures - since this throws away compile
    > time type checking.
    >
    > Has anyone got any ideas as to how we could do this? (Unless you use a

    type
    > library, ASP queries the CCW for type information - although what is
    > returned can be changed by overriding the correct method(s) in the

    object's
    > IReflect interface).
    >
    > We have come up with a number of ideas which include writing a wrapper

    class
    > which customises IDispatch by overriding IReflect, but does anyone have a
    > simpler solution? Are there any commercial components which can solve this
    > problem? We also considering using web services but I don't think that we
    > would get the same OO semantics using this approach, would we? We could
    > write a simple .NET wrapper class for each .NET class or we could add

    extra
    > methods to the original class in order to solve this problem. Writing a
    > wrapper object in COM has also been considered, as has passing the data as

    a
    > string (which would not be very transparent, it would be inefficient). We
    > also considered writing our own collection classes which we would us

    instead
    > of arrays, but it might be difficult to make this transparent.
    >
    > Any ideas would be really appreciated..
    >
    > Thanks
    >
    > Mark
    >
    >
     
    Peter Strøiman, Dec 10, 2003
    #4
    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. Replies:
    0
    Views:
    417
  2. Chris Newby
    Replies:
    0
    Views:
    1,994
    Chris Newby
    Jul 26, 2006
  3. Replies:
    13
    Views:
    1,129
  4. Rhek

    ASP Classic and .Net Components

    Rhek, Aug 29, 2005, in forum: ASP General
    Replies:
    1
    Views:
    173
    Jeff Cochran
    Aug 30, 2005
  5. Robert Miller

    using .net components with classic ASP web pages

    Robert Miller, Jan 6, 2006, in forum: ASP General
    Replies:
    3
    Views:
    192
    AnthonyWJones
    Jan 6, 2006
Loading...

Share This Page