I am trying to create a simple web application using ASP.NET and Interop COM.
The main question: how to make Interop COM work on the client side?
I use:
IIS Windows Server 2008
C # Interop COM - Visual Studio 2010
Asp.NET - Visual Studio 2010
Having looked at these articles
http://msdn.microsoft.com/en-us/library/aa479302.aspx and http://msdn.microsoft.com/en-us/magazine/cc301832.aspx . I tried using the client side component in two ways:
Firstly:
<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 the .cs file:
RegisterClientScriptBlock("showSaveMessage", "<script language=\"JavaScript\"> Obj.PrintHi(); </script>");
On the server side, I open Internet Explorer and works like a charm. But on the client side appears: Object does not support this property or method.
:
<%
set Obj = CreateObject("MyApp.MyClass")
Obj.PrintHi
%>
, MyApp.dll .
? COM ? IIS, Object, ?
Advance
1 #
ASP.NET # Visual Studio 2010 Windows XP 32bits, # Interop COM.
"Windows XP" IE . .
, Windows Server 2008 IIS. IIS, IE, .
. IE Windows XP , Windows Server, , , , : " ".
:
Windows 2008 R2 64bit
IE 9
:
Windows XP 32bits
IE 8
2 #
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";
}
}
}
AssemblyInf.cs [assembly: ComVisible(true)]
asp:
<%@ 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>
IE, ActiveX .
Windows XP , Windows Server . Windows XP "Windows XP call Windows 2008": " "
regasm /u MyCOM.dll, IE .
Dll C:\WINDOWS\Downloaded Program Files, , CONFLICT.1.. C:\WINDOWS\Downloaded Program Files\CONFLICT.1 . regasm MyCOM.dll /codebase.
.NET: C:\Windows\Microsoft.NET\Framework\v4.0.30319
.NET: C:\Windows\Microsoft.NET\Framework\v4.0.30319
? .
3 #
"". IE ActiveX. . Windows XP Client. , ActiveX . .
Interop COM ASP. , : Object . , Safe Inicialization. : http://msdn.microsoft.com/en-us/library/aa751977.aspx#iobjsafe, ++, #?
4 #
:
public class ClassTest : System.Windows.Forms.UserControl, IClassTest
.cab , .
wpf? ?