473,385 Members | 1,730 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,385 software developers and data experts.

Please help; what am I doing wrong with 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 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.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
1 1264
On Sun, 05 Feb 2006 07:34:54 +0000, intrader wrote:
I have worked out a solution - what made it work is the the attribute:
[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(StrToByteAr ray(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.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

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

Similar topics

40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
17
by: VM | last post by:
In my Windows app, I'm running a batch process that's composed of a FOR loop that'll run 15,000 times (datatable row count), copy cthe data of each row -3 fields- to a struct, and send the strct to...
2
by: Andrew S. Giles | last post by:
OK, Ive run my head into this wall for too long. I need help. I am developing an applicaiton in C# to present a user with a GUI to specify a configurable list of machines that he wants to listen...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
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....
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
5
by: Michael Russell | last post by:
Hi all, Using C#, I've created a simple wrapper class for using Excel. I have Office Pro 2003 installed on my devel machine. The wrapper class works great, reading and writing to/from Excel. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.