5

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Cobaia
  • 1,503
  • 3
  • 22
  • 41
  • Do you have your COM dll registered at client side? It will never work if you don't – yms Aug 04 '11 at 16:55
  • @yms Yes, I did. I registered with regasm MyApp.dll /codebase. – Cobaia Aug 04 '11 at 16:57
  • Is your "client side" a 64 bit OS? if it is, maybe you need to register your dll for both architectures. See [this answer in SO](http://stackoverflow.com/questions/372140/c-com-dll-do-i-use-regasm-or-regsvr32/372197#372197) for details. – yms Aug 04 '11 at 17:19
  • @yms My "client side" is Windows XP 32bits. I do not have the folder 'Framework64' :( – Cobaia Aug 04 '11 at 17:31
  • @yms In IIS I marked in V4.0.NET to enable 32bits application, but the same message appears "Object doesn't support this property or method" in client side. Thanks – Cobaia Aug 04 '11 at 17:57
  • Whatever you do on your server, it will not affect the result on client side. That is why I asked if you registered your dll on the client side. I think you should post a bit more details on the diferences between the test you are doing on your server (the one that works) and the test on the client. Example: Browser flavor+version, OS, CPU architecture. – yms Aug 04 '11 at 18:00
  • @yms I added 1# Update to Question. – Cobaia Aug 04 '11 at 18:22
  • fyi, "ASP.NET" is one word, with no space between. – John Saunders Aug 04 '11 at 19:52
  • @yms I will try safe inicialization. http://msdn.microsoft.com/en-us/library/aa751977.aspx. Is there C# examples? – Cobaia Aug 05 '11 at 17:19

2 Answers2

3

I found the solution: Deploy C# ActiveX in a CAB for Internet Explorer use

I did the following:

Strong-named the assembly.
Created an INF file
Created an MSI using the Visual Studio 2010 "Setup Project" template.
Created a CAB file using "Makecab.exe"

See this link for details to mark as safe for scripting http://www.olavaukan.com/2010/08/creating-an-activex-control-in-net-using-c/

I was searching wrong, not is Component COM C# and yes C# ActiveX Control. I confuse with ATL COM C++.

Thank you

Community
  • 1
  • 1
Cobaia
  • 1,503
  • 3
  • 22
  • 41
0

To get something working like this on the client side, provided it can be done with the security settings on the client machine, you have to have the DLL registered. Considering this requirement to make your website work, I would think a windows application of some type (winForms, WPF, even newer Silverlight) might be a better option as you can make sure the COM bits (or native bits, in cases where using native) are installed.

One issue with COM is the identifier has to be registered (i.e. in the registry) to work, as that is the only pointer Windows has to find the bits.

Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32
  • Thanks for reply. How can I make it? I make another simple application. But does not work. Se 2# Update – Cobaia Aug 05 '11 at 14:26
  • I think the problem has to do with (safe inicialization). But the example was in C++ http://msdn.microsoft.com/en-us/library/aa751977.aspx. I will find C# examples. – Cobaia Aug 05 '11 at 17:17
  • Are saying that I can not use Class Library Project? Have I to use Wpf Custom Control Library Project to make it work? – Cobaia Aug 05 '11 at 19:18
  • What is the actual business requirement. Not the requrement with your thought out solution, but "As a user, I need to be able to have a page print automatically when I hit the page" or similar. If you can state the actual business requirement, there is likely another solution to a COM component on the client side triggered from code sent by the server. – Gregory A Beamer Aug 08 '11 at 14:27
  • My mistake was to confuse ATL COM C++ with C# ActiveX Control. And search for COM components in C#, the correct is ActiveX Control in C#. Sorry for the inconvenience. – Cobaia Aug 08 '11 at 15:15