c# - 将 c# DLL 暴露给 VB6 时出错

标签 c# wcf vb6

我想问一下如何正确地将我的 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 上使用它但它返回一个

runtime erro 429 which says Acvtive X component cant create object.

Dim testBillerV10 As V10Bridge.testBillerV10
Set testBillerV10 = New testBillerV10

最佳答案

尝试 2 处更改。首先你的类需要一个 ProgID 属性(我不使用 ComSourceInterfaces 所以我去掉了它):

[Guid("116CCA1E-7E39-4515-9849-90790DA6431E")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[ProgID("MyNameSpace.TestBillerV10")]
public class TestBillerV10 : ITestBillerV10Service

您的界面需要一个 GuidInterfaceType:

[Guid("782AB14D-BE28-4b47-9498-DFF94B457E6D")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface ITestBillerV10Service

关于c# - 将 c# DLL 暴露给 VB6 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986262/

相关文章:

vb6 - For 每个循环立即退出

vb6 - 通过拖动鼠标滚动图像

c# - 二维 javascript 数组到 c# 数据表?

wcf - 是否有适用于 Glimpse 的 WCF 插件?

VBA\VB6 - 将数字转换为日期

wcf - 适用于辅助角色云服务的 Windows Azure 控制台

c# - WCF 不活动超时

c# - "this"运算符(operator)不工作

c# - 无法转换泛型

c# - 添加dll以发布