Calling a remote COM+ ServicedComponent from a C# client

爱⌒轻易说出口 提交于 2019-12-21 13:02:26

问题


I have a serviced component installed in a COM+ server application. I want to create an instance from a remote client. The client needs to be able to specify the server machine's name dynamically. How do I do this?

I tried using Activator:

            (XSLTransComponent.XSLTransformer)Activator.GetObject(
                        typeof(XSLTransComponent.XSLTransformer),
                        serverName
                        );

But I get this:

System.Runtime.Remoting.RemotingException: Cannot create channel sink to connect to URL 'server'. An appropriate channel has probably not been registered. at System.Runtime.Remoting.RemotingServices.Unmarshal(Type classToProxy, String url, Object data)

Do I need to register a channel? If so, how?

Another idea is to use Marshall.BindToMoniker, but how do I specify a moniker for a remote object hosted on COM+ on server x?


回答1:


Eureka! This works:

string serverName = serverTextBox.Text;
Type remote = Type.GetTypeFromProgID("XSLTransComponent.XSLTransformer", serverName);
return (XSLTransComponent.XSLTransformer)Activator.CreateInstance(remote);

Thanks to this question



来源:https://stackoverflow.com/questions/485000/calling-a-remote-com-servicedcomponent-from-a-c-sharp-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!