当我尝试从远程PC调用COM +对象的方法时,出现错误:
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'System.EnterpriseServices.IRemoteDispatch'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6619A740-8154-43BE-A186-0319578E02DB}' failed due to the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
Source=System.EnterpriseServices
StackTrace:
at System.EnterpriseServices.RemoteServicedComponentProxy.Invoke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ComCalculator.Calculator.Sum(Int32 a, Int32 b)
at ConsoleApp1.Program.Main(String[] args)
我在ServerPC和ClientPC上运行它。在ServerPC上,一切正常。在ClientPC上,调用c.Sum(34, 65)
时出现错误0x80070005。
在“组件服务”->“我的电脑”->“属性”->“ COM安全性”中,我添加并授予了本地用户访问权限,网络服务和匿名登录。我也在Windows注册表中为GUID为{6619A740-8154-43BE-A186-0319578E02DB}的项目添加了此帐户,但这无济于事。
dll:
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(false)]
namespace ComCalculator
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComponentAccessControl(false)]
public class Calculator : ServicedComponent
{
[AutoComplete(true)]
public int Sum(int a, int b)
{
return a + b;
}
}
}
客户端:
ComCalculator.Calculator c = new ComCalculator.Calculator();
var res = c.Sum(34, 65);
答案 0 :(得分:0)
ServerPC和ClientPC不在一个域中,因此我需要两台PC上具有相同登录名和密码的用户。