I would like to ask how will I properly exposed my C# DLL to vb6. The purpose of exposing the dll is to consume a WCF service for a VB6 Application since it cant consume directly the Wcf Service.
Below is the code in c#
[Guid("116CCA1E-7E39-4515-9849-90790DA6431E")]
[ClassInterface(ClassInterfaceType.None),ComSourceInterfaces(typeof(ITestBillerV10Service))]
[ComVisible(true)]
public class TestBillerV10 : ITestBillerV10Service
{
TestBillerInquiry.TestBillerInquiryClient _TestBillerInquiry;
public TestBillerV10()
{
_TestBillerInquiry = new TestBillerInquiry.TestBillerInquiryClient();
System.Net.ServicePointManager.Expect100Continue = false;
}
/// <summary>
/// Inquire if account no is valid or not
/// </summary>
/// <param name="accountNo">Account No. to check</param>
/// <param name="userId">User Id of the terminal</param>
/// <returns>string array Index[0] = response Code(Yes/No), Index[1] = Description for Response, Index[2] = Error Code if response code is No</returns>
[ComVisible(true)]
[DispId(1)]
public string[] Inquiry(string accountNo, string userId)
{
var newInquiry = new TestBillerInquiry.TestBillerInquiryRequest {AccountNumber = accountNo, UserId= userId };
TestBillerInquiry.TestBillerInquiryResponse response = _TestBillerInquiry.Inquiry(newInquiry);
var retVal = new string[3];
retVal[0] = response.Response;
retVal[1] = response.Message;
retVal[2] = response.Error;
return retVal;
}
}
and simple interface below
/// <summary>
/// Inquire if account no is valid or not
/// </summary>
/// <param name="accountNo">Account No. to check</param>
/// <param name="userId">User Id of the terminal</param>
/// <returns>string array Index[0] = response Code(Yes/No), Index[1] = Description for Response, Index[2] = Error Code if response code is No</returns>
[ComVisible(true)]
public interface ITestBillerV10Service
{
[DispId(1)]
string[] Inquiry(string accountNo, string userId);
}
Below is how I try to consume it on vb6 but it returns a
runtime erro 429 which says Acvtive X component cant create object.
Dim testBillerV10 As V10Bridge.testBillerV10
Set testBillerV10 = New testBillerV10
Try 2 changes. First your class needs a ProgID
attribute (and I don't use ComSourceInterfaces
so I got rid of it):
[Guid("116CCA1E-7E39-4515-9849-90790DA6431E")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[ProgID("MyNameSpace.TestBillerV10")]
public class TestBillerV10 : ITestBillerV10Service
Your interface needs a Guid
and InterfaceType
:
[Guid("782AB14D-BE28-4b47-9498-DFF94B457E6D")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface ITestBillerV10Service
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.