【问题标题】:Error in exposing c# DLL to VB6将 c# DLL 暴露给 VB6 时出错
【发布时间】:2013-08-01 21:04:54
【问题描述】:

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

运行时错误 429,表示 Acvtive X 组件无法创建对象。

Dim testBillerV10 As V10Bridge.testBillerV10
Set testBillerV10 = New testBillerV10

【问题讨论】:

    标签: c# wcf vb6


    【解决方案1】:

    尝试 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      相关资源
      最近更新 更多