473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Urgent, I need your help with ASP to .net interop

I have a .NET interop assembly Hash.MD5Sum with two methods Identity and
GetMD5Sum.
I want to call the methods from ASP (JScript), The debugger tells me that
object oMD5Sum has only one method (ToString()). How do I get the
Identity and GetMD5Sum methods to be accessible?

I include the entire .net assembley followed by a snippet of the ASP code.

/////The code of the .NET assembly is:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
[assembly:
GuidAttribute("3F7E9E2F-33DE-473e-BCEF-ABD161A5C2F4")]

namespace Hash
{
/// <summary>
/// Summary description for IHop.
/// </summary>
///
[GuidAttribute("66E6B7CB-6E8A-4396-A916-DB761AAAB65C")]
public interface IMD5Sum
{
string Identity();
string GetMD5Sum(string toDigest);
}

/// <summary>
/// This class provides the MD5Sum hash.
/// </summary>
[GuidAttribute("5D701679-CB67-4e23-A83B-099AC85B175E")]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDua l)]
[ProgIdAttribute("Hash.MD5Sum")]
public class MD5Sum
{
public MD5Sum()
{
}
// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=
new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public string Indentity()
{
return "How are you doing?";
}
public string GetMD5Sum(string toDigest)
//Output: string<-> input: string //
{
return BitConverter.ToString(new
MD5CryptoServiceProvider().
ComputeHash(StrToByteArray(toDigest))).
Replace("-","").ToLower();


///End of the .Net Assembly

In the ASP I do the following:

////Code in the ASP
<script language="jscript" type="text/javascript" runat="server">

debugger;
var oMD5Sum = Server.CreateObject("Hash.MD5Sum");
var sIdentity = oMD5Sum.Identity();
var sDigest = oMD5Sum.GetMD5Sum("hey foo");
</script>

Thanks for your help!
Feb 5 '06 #1
2 1851
Hi there, I made a small correction in your code:

-- BEGIN CODE --
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;

namespace Hash
{

/// <summary>
/// Summary description for .
/// </summary>
///
[GuidAttribute("66E6B7CB-6E8A-4396-A916-DB761AAAB65C")]
public interface IMD5Sum
{
string Identity();
string GetMD5Sum(string toDigest);
}

/// <summary>
/// This class provides the MD5Sum hash.
/// </summary>
[GuidAttribute("5D701679-CB67-4e23-A83B-099AC85B175E")]
[ProgIdAttribute("Hash.MD5Sum")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class MD5Sum : IMD5Sum
{
[ComVisible(true)]
public string Identity()
{
return "How are you doing?";
}

[ComVisible(true)]
public string GetMD5Sum(string toDigest)
{
return BitConverter.ToString(new
MD5CryptoServiceProvider().
ComputeHash(StrToByteArray(toDigest))).
Replace("-","").ToLower();
}

public MD5Sum()
{
}

// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=
new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

}

}
-- END CODE --

after registering MIDL description looks as expected:

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: HashLibrary.tlb

[
uuid(C6664976-58D8-3FCC-88D5-E65E1F4520BA),
version(1.0),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, HashLibrary,
Version=1.0.2228.23928, Culture=neutral, PublicKeyToken=null)

]
library HashLibrary
{
// TLib : // TLib : Common Language Runtime Library :
{BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface IMD5Sum;
interface _MD5Sum;

[
odl,
uuid(66E6B7CB-6E8A-4396-A916-DB761AAAB65C),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.IMD5Sum)

]
interface IMD5Sum : IDispatch {
[id(0x60020000)]
HRESULT Identity([out, retval] BSTR* pRetVal);
[id(0x60020001)]
HRESULT GetMD5Sum(
[in] BSTR toDigest,
[out, retval] BSTR* pRetVal);
};

[
uuid(5D701679-CB67-4E23-A83B-099AC85B175E),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.MD5Sum)
]
coclass MD5Sum {
[default] interface _MD5Sum;
interface _Object;
interface IMD5Sum;
};

[
odl,
uuid(53C1EC30-BAE4-31FF-973B-BD911C76F0D8),
hidden,
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.MD5Sum)

]
interface _MD5Sum : IDispatch {
};
};
--
Milosz Skalecki
MCP, MCAD
"intrader" wrote:
I have a .NET interop assembly Hash.MD5Sum with two methods Identity and
GetMD5Sum.
I want to call the methods from ASP (JScript), The debugger tells me that
object oMD5Sum has only one method (ToString()). How do I get the
Identity and GetMD5Sum methods to be accessible?

I include the entire .net assembley followed by a snippet of the ASP code.

/////The code of the .NET assembly is:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
[assembly:
GuidAttribute("3F7E9E2F-33DE-473e-BCEF-ABD161A5C2F4")]

namespace Hash
{
/// <summary>
/// Summary description for IHop.
/// </summary>
///
[GuidAttribute("66E6B7CB-6E8A-4396-A916-DB761AAAB65C")]
public interface IMD5Sum
{
string Identity();
string GetMD5Sum(string toDigest);
}

/// <summary>
/// This class provides the MD5Sum hash.
/// </summary>
[GuidAttribute("5D701679-CB67-4e23-A83B-099AC85B175E")]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDua l)]
[ProgIdAttribute("Hash.MD5Sum")]
public class MD5Sum
{
public MD5Sum()
{
}
// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=
new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public string Indentity()
{
return "How are you doing?";
}
public string GetMD5Sum(string toDigest)
//Output: string<-> input: string //
{
return BitConverter.ToString(new
MD5CryptoServiceProvider().
ComputeHash(StrToByteArray(toDigest))).
Replace("-","").ToLower();


///End of the .Net Assembly

In the ASP I do the following:

////Code in the ASP
<script language="jscript" type="text/javascript" runat="server">

debugger;
var oMD5Sum = Server.CreateObject("Hash.MD5Sum");
var sIdentity = oMD5Sum.Identity();
var sDigest = oMD5Sum.GetMD5Sum("hey foo");
</script>

Thanks for your help!

Feb 6 '06 #2
Thank you so much for your solution.

Over the weekend I also figured a solution that entails using the
attribute:
[ClassInterface(ClassInterfaceType.None)]

This attribute also turns on [default] on the coclass entry in the .tlb
olisting.

There are apparently many ways to solve the problem.
(I put my corrected code all the way at the bottom)
On Mon, 06 Feb 2006 05:40:23 -0800,
Milosz Skalecki wrote:
Hi there, I made a small correction in your code:

-- BEGIN CODE --
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;

namespace Hash
{

/// <summary>
/// Summary description for .
/// </summary>
///
[GuidAttribute("66E6B7CB-6E8A-4396-A916-DB761AAAB65C")]
public interface IMD5Sum
{
string Identity();
string GetMD5Sum(string toDigest);
}

/// <summary>
/// This class provides the MD5Sum hash.
/// </summary>
[GuidAttribute("5D701679-CB67-4e23-A83B-099AC85B175E")]
[ProgIdAttribute("Hash.MD5Sum")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class MD5Sum : IMD5Sum
{
[ComVisible(true)]
public string Identity()
{
return "How are you doing?";
}

[ComVisible(true)]
public string GetMD5Sum(string toDigest)
{
return BitConverter.ToString(new
MD5CryptoServiceProvider().
ComputeHash(StrToByteArray(toDigest))).
Replace("-","").ToLower();
}

public MD5Sum()
{
}

// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=
new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}

}

}
-- END CODE --

after registering MIDL description looks as expected:

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: HashLibrary.tlb

[
uuid(C6664976-58D8-3FCC-88D5-E65E1F4520BA),
version(1.0),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, HashLibrary,
Version=1.0.2228.23928, Culture=neutral, PublicKeyToken=null)

]
library HashLibrary
{
// TLib : // TLib : Common Language Runtime Library :
{BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface IMD5Sum;
interface _MD5Sum;

[
odl,
uuid(66E6B7CB-6E8A-4396-A916-DB761AAAB65C),
version(1.0),
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.IMD5Sum)

]
interface IMD5Sum : IDispatch {
[id(0x60020000)]
HRESULT Identity([out, retval] BSTR* pRetVal);
[id(0x60020001)]
HRESULT GetMD5Sum(
[in] BSTR toDigest,
[out, retval] BSTR* pRetVal);
};

[
uuid(5D701679-CB67-4E23-A83B-099AC85B175E),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.MD5Sum)
]
coclass MD5Sum {
[default] interface _MD5Sum;
interface _Object;
interface IMD5Sum;
};

[
odl,
uuid(53C1EC30-BAE4-31FF-973B-BD911C76F0D8),
hidden,
dual,
oleautomation,
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Hash.MD5Sum)

]
interface _MD5Sum : IDispatch {
};
};

///CORRECTED CODE FOLLOWS:
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace Hash
{
/// <summary>
/// This namespace contains classes that represent hashes.
/// </summary>
[GuidAttribute("B508ED0D-A4A2-4f21-8F5F-BF756544976E")]
public interface IMD5Sum
{
string GetIdentity();
string GetMD5Sum(string toDigest);
}

/// <summary>
/// This class represents the MD5Sum hash.
/// </summary>
[ClassInterface(ClassInterfaceType.None)]
[GuidAttribute("3F84EA01-E096-4305-B936-21043581CAB7")]
public class MD5Sum : IMD5Sum
{
public MD5Sum()
{
}
// Converts a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
public string GetIdentity()
{
return "How are you doing?";
}

public string GetMD5Sum(string toDigest) //Output: string<-> input: string //
{
return BitConverter.ToString(new
MD5CryptoServiceProvider().ComputeHash(StrToByteAr ray(toDigest))).Replace("-","").ToLower();

}
}
}

Feb 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Reza | last post by:
This looked pretty simple to me at first, and perhaps it still is, but I havnt been able to find out just what the trick is. Basically the aim is to compile a dll from VB .NET, which can be read...
1
by: Nadav | last post by:
Hi, Introduction *************** I have a system build of a collection of 'Native COM objects' and '.NET COM interop' objects, all of the COM objects are managed through a 'Native COM' layer,...
1
by: em | last post by:
Hi all, I'm getting some problems importing a DLL that I made in C# within VB6.0. The C# is quite easy, just for trying: namespace TestDll { public class Class1
3
by: Mark Keogh | last post by:
Hi, Why is everything some confusng when MS are involved ;-) Anyway, I have my excel export routines working fine, now when I try to build them into my assembly, which has a strong name, I get...
11
by: scorpion53061 | last post by:
in my head...... I need my application to work with Office 97, 2000, XP and 2003 versions of MS Word and MS Excel. IN order to acomplish this I have to install in different folders: 1....
3
by: Danny Tuppeny | last post by:
Hi all, This is quite urgent - I'll keep it brief... I've posted the WSDL, Proxy class etc. here: http://dantup.me.uk/SoapProb/ My problem is that the Soap Envelope looks fine, yet the...
1
by: John | last post by:
Hi all, I did post this about 10 hours ago thinking I would have received an answer now but it is quite urgent. How do I add a COM object to a web form? I notice there's a primary interop...
13
by: Niyazi | last post by:
Hi I have a report that I have to run it monthly in my machine. My code in VB.NET and I access AS400 to get data, anaysie it and send into pre formated Excel sheet. The data consist of 9000...
0
by: Carlos Lozano | last post by:
Hello, I am converting a MS Access application into ASP.NET. It has a many CR reports that calls external functions in a VBA library. I have been trying to create a user Function Library (UFL)...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.