I am trying to make a simple web application using ASP.NET and Interop COM.
The main question is: How to make Interop COM works in client side?
I am Using:
IIS Windows Server 2008
C# Interop COM - Visual Studio 2010
Asp .NET - Visual Studio 2010
After looking at these articles
http://msdn.microsoft.com/en-us/library/aa479302.aspx
and http://msdn.microsoft.com/en-us/magazine/cc301832.aspx.
I tried to use the component on the client side in two ways:
First:
<object id="Obj" codebase="MyApp.dll#version=1,0,0,0" classid="clsid:C6659361-1625-4746-931C-36014B146679" VIEWASTEXT></object>
<script type="text/javascript" >
function test() {
alert('TEst');
Obj.PrintHi();
alert('and');
}
</script>
Second: in .aspx
<object id="Obj" codebase="MyApp.dll#version=1,0,0,0" classid="clsid:C6659361-1625-4746-931C-36014B146679" VIEWASTEXT></object>
and in .cs file:
RegisterClientScriptBlock("showSaveMessage", "<script language=\"JavaScript\"> Obj.PrintHi(); </script>");
In server side I open Internet Explorer and works like a charm. But in client side appears: Object doesn't support this property or method.
I also tried:
<%
set Obj = CreateObject("MyApp.MyClass")
Obj.PrintHi
%>
Works for both side, but only call MyApp.dll installed on the server side.
Using 'object tag' is the correct way? Is there another way to use COM in client side? How to configure IIS to avoid Object doesn't support this property or method in client side?
Thanks in Advance
1# Update
I create ASP.NET C# in Visual Studio 2010 on Windows XP 32bits that uses a C# Interop COM.
On my machine "Windows XP" I do Start Debugging and IE page opens with my application. This works.
So I copied the project to Windows Server 2008 and added the project in IIS. When I run IIS opens IE and this works.
After this I tried to make the final test, So I open the IE on Windows XP and type the address that Windows Server generated, fine, I can see the page, but when I click to run the function, Appears: "Object does not support this property or method".
Server:
Windows 2008 R2 64bits
IE version 9
Client:
Windows XP 32bits
IE version 8
2# Update
I tried another test
I made a new Component COM
IClassTest.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace MyCOM
{
[ComVisible(true)]
[Guid("8F388924-7743-4166-993F-CBF897D08A8B")]
public interface IClassTest
{
string getString(string str);
}
}
ClassTest.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace MyCOM
{
[ComVisible(true)]
[Guid("1AE4AD64-A951-4E6C-8600-AA1F08810DDD")]
public class ClassTest : IClassTest
{
public string getString(string str)
{
return str + "1";
}
}
}
In AssemblyInf.cs has [assembly: ComVisible(true)]
I made another asp application:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="asp_test._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<object id="Obj" codebase="MyCOM.dll#version=1,0,0,0" classid="clsid:1AE4AD64-A951-4E6C-8600-AA1F08810DDD" VIEWASTEXT></object>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript" >
function test() {
var test = Obj.getString('2');
alert(test);
}
</script>
<input name="btnTest" value="Call COM" onclick="test()" style=" width: 400px;" type="button">
</asp:Content>
I change IE settings to display ActiveX not trust and run the program. In windows XP works, In Windows Server works. But when try to call the page from windows XP "Windows XP call Windows 2008 page" appears: "Object doesn't support this property or method"
If on client side I do regasm /u MyCOM.dll
the IE prompted to install the component.
The dll is stored in the C:\WINDOWS\Downloaded Program Files
, if I try to install more than once, creates a folder called CONFLICT.1
.. C:\WINDOWS\Downloaded Program Files\CONFLICT.1
very strange. I also tried to register this downloaded component with regasm MyCOM.dll /codebase
.
Server .NET: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Client .NET: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Why not work? It makes no sense.
3# Update
I ran on another machine "Client". I change IE settings to run not safe ActiveX. And Works, After this I tried on Windows XP Client I reseted the settings and set up again to run ActiveX not safe. This Works.
Now the problem is related to Install Interop COM from ASP. I tried to install but appears: Object doesn't support this property or method. I think it is related to Safe Inicialization
. I found this link: http://msdn.microsoft.com/en-us/library/aa751977.aspx#iobjsafe but is for C++, Is there C# examples?
4# Update
I tried to use:
public class ClassTest : System.Windows.Forms.UserControl, IClassTest
I also tried to do a .cab file but does not work.
Have I to make wpf project? Why this does not work?