我想问一下如何将我的C#DLL正确地暴露给vb6。 暴露dll的目的是为VB6应用程序使用WCF服务,因为它无法直接使用Wcf服务。
以下是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;
}
}
和下面的简单界面
/// <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);
}
下面是我尝试在vb6上使用它但它返回
的方法运行时erro 429,表示Acvtive X组件无法创建对象。
Dim testBillerV10 As V10Bridge.testBillerV10
Set testBillerV10 = New testBillerV10
答案 0 :(得分:0)
尝试2次更改。首先,您的班级需要ProgID
属性(我不使用ComSourceInterfaces
所以我摆脱了它):
[Guid("116CCA1E-7E39-4515-9849-90790DA6431E")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[ProgID("MyNameSpace.TestBillerV10")]
public class TestBillerV10 : ITestBillerV10Service
您的界面需要Guid
和InterfaceType
:
[Guid("782AB14D-BE28-4b47-9498-DFF94B457E6D")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface ITestBillerV10Service