Please help; what am I doing wrong with interop

I

intrader

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 one the ToString() method. 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.AutoDual)]
[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!
 
I

intrader

[ClassInterface(ClassInterfaceType.None)] - this tells COM that the
default interface is the first one implemented in the class.
The correct code for the .cs files in included
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 one the ToString() method. 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.
For anyone interested the corrected one: ///Corrected code 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(StrToByteArray(toDigest))).Replace("-","").ToLower();

}
}
}

///End of Corrected 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.AutoDual)]
[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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top