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

M

Mark

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
 
K

Kevin Spencer

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.
 
M

Matthew W. Jackson

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
 
P

Peter Strøiman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top