C# Interop with Remote COM Object

G

Guest

I'm having trouble connecting to a remote COM object using Reflection. I've
got a Web Form using C# that needs to connect to a COM object on a remote
server. The snippet of code that follows is what I've got (and found through
all of my research as the necessary code):

Type remoteType = Type.GetTypeFromProgID(r2wprogid, r2wserver) ;
object remoteObject = Activator.CreateInstance(remoteType, true) ;

The call to the Activator.CreateInstance continually causes an exception
stating that the remote server is unavailable. However, if I run the
associated code in my old 'standard ASP' page, there is no problem connecting
and performing my function calls.

Can anyone see something specific that I'm missing that would cause my Web
Form to be unable to connect to the remote server? Any ideas and suggestions
would be appreciated.
 
N

Nicholas Paldino [.NET/C# MVP]

Bryan,

By default, ASP.NET runs under the ASPNET local account, which doesn't
have access to the network. Since you are trying to access an object over
the network, it is most likely that it is failing here.

What you need to do is run the page under a user account which can
access the object on the network. You can do this through impersonation
(using the WindowsImpersonationContext class), or by setting the identity
tag in the web.config file appropriately.

To verify this is the issue, create a windows forms application, and try
making the same call. If it succeeds, then the solution above should work.

Hope this helps.
 
G

Guest

Nicholas,

Thanks for your post and suggestion. Unfortunately, I have the identity tag
in the web.config file set to impersonate. I did, however, try your
suggestion of creating a Windows app to see if I could get the COM object to
instantiate successfully and was unable to get that to work either.

Any other suggestions?

Thanks,
Bryan Tubbs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top