简体   繁体   English

简单的COM +服务器引发意外异常

[英]Simple COM+ server throws unexpected Exception

I wrote a simple ServicedComponent 我写了一个简单的ServicedComponent

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.EnterpriseServices;

namespace ComPlusServer
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid("9C674ECA-1B71-42EA-9DB2-9A0EA57EC121")]
    [Description("Hello Server")]
    public class HelloServer : ServicedComponent
    {
        [Description("Say Hello!")]
        public String SayHello()
        {
            return "Hello!, "; 
        }
    }
}

and a Windows Forms application 和Windows窗体应用程序

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComPlusServer;

namespace Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HelloServer server = new HelloServer();

            MessageBox.Show(server.SayHello(), "Message from HelloServer");
        }
    }
}

on the Component Services MMC, on the application properties, security tab I lowered Authentication Level for Calls to None and Impersonation Level to Identify and Unchecked Enforce access checks for this application on Authorization. 在组件服务MMC的应用程序属性的“安全性”选项卡上,我将“呼叫的身份验证级别”降低为“ 无” ,将“身份验证级别”降低为“ 识别和取消选中”,从而在授权时对此应用程序执行访问检查。

I keep getting a ServicedComponentException exception saying 我不断收到ServicedComponentException异常说

Method-level role based security requires an interface definition for class method. 基于方法级角色的安全性需要类方法的接口定义。

Any idea on this? 有什么想法吗?

I believe that it means that methods of your Component class needs to be defined in an interface. 我认为这意味着需要在接口中定义Component类的方法。

[ComVisable(true)]
public interface IHelloServer
{
    public String SayHello(); 
}

Now have your componet class implement the interface: 现在让您的componet类实现该接口:

[ComVisable(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComDefaultInterface(typeof(IHelloServer))]     
[Guid("9C674ECA-1B71-42EA-9DB2-9A0EA57EC121")]     
[Description("Hello Server")]     
public class HelloServer : ServicedComponent, IHelloServer     
{         
    [Description("Say Hello!")]         
    public String SayHello()         
    {             
        return "Hello!, ";          
    }     
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM