Urgent, I need your help with ASP to .net 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 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.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!
 
G

Guest

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 said:
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.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

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)


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(StrToByteArray(toDigest))).Replace("-","").ToLower();

}
}
}
 

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

Top