Re: Calling C# COM object from JavaScript
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 8 Feb 2008 13:35:11 -0500
Justin,
You should expose the class through COM interop and then pass that to
your method. The reason for this is that the object that you are passing
from javascript is a makeshift implementation of IDispatch, which doesn't
have the same type as the object you created in .NET.
You could use reflection to set the properties of the javascript object
passed in, but that's hackney.
Expose the object in your .NET code as another COM object, and create an
instance of that in javascript and pass it into your method.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
<Justin30324@xxxxxxxxx> wrote in message
news:bf936f4f-de52-45ae-951b-25fbf0c7a905@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Nicholas,
Thank you very much for your answers. Here is what I'm doing in my
JavaScript now:
function strObject()
{
this.str1;
this.str2;
return this;
}
var myStrObject = new strObject();
myObject.CallMe2(myStrObject);
Now I'm passing a JavaScript object into the C# COM function. I should
be able to manipulate the properties of that object in the C#
function. I have a set up a class in C# to mimic the object in
JavaScript. (I know it's bad practice to have everything public like
this - I'm just trying to get it working.)
Here is the C# code:
public class MyStringClass
{
public string str1;
public string str2;
}
And here is the new function exposed in the COM object:
public void CallMe2(MyStringClass mySC)
{
mySC.str1 = "Hello";
mySC.str2 = "world";
}
When I make the JavaScript call to the C# COM function (see above), it
hits the error handler in JavaScript. The number of the error is
-2146827858. The error description is:
Class doesn't support Automation.
What am I doing wrong? Thanks again.
Justin
.
- References:
- Calling C# COM object from JavaScript
- From: Justin30324
- Re: Calling C# COM object from JavaScript
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Calling C# COM object from JavaScript
- From: LVP
- Re: Calling C# COM object from JavaScript
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Calling C# COM object from JavaScript
- From: Justin30324
- Calling C# COM object from JavaScript
- Prev by Date: Re: if file exist on the net
- Next by Date: Re: 22 New Features of Visual Studio 2008 for .NET Professionals
- Previous by thread: Re: Calling C# COM object from JavaScript
- Next by thread: Re: Calling C# COM object from JavaScript
- Index(es):
Relevant Pages
|