问题
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