Dynamically linking to webservice or COM DLL

L

lavu

I have a C# client application that uses a COM DLL(written in C++) or
a webservice (the
webservice is the same COM DLL wrapped up as a webservice). The client
can dynamically (based on form input) select to use the webservice or
the DLL. The front end interface and the implementaion code is the same

in either case. However the namespace and the main class used in either

case are different.
Is there anyway to implement this efficiently ?
Thanks in advance.
 
N

Nicholas Paldino [.NET/C# MVP]

lavu,

The best way to do this would be to use an interface, and implement a
class factory pattern. The COM object and the proxy would both implement
the interface, and then you can have a class factory create an
implementation when needed, based on the circumstances.

Hope this helps.
 
L

lavu

Thank you. I am not familiar with the class factory pattern and am
going to read more about it.
 
L

lavu

I am re- introducing this thread after exploring the Class Factory
Pattern and
determining that it would not be suitable for me. The main reason is
that
the base class needs to be the same for both and in my case, the web
service and
the COM implementation does not have a common base class.
Are there any other ideas to implement this ?
 
N

Nicholas Paldino [.NET/C# MVP]

lavu,

For a class factory to work, they don't necessarily have to have the
same base class. They can share the same interface implementation. You CAN
do this in this case, which is what I actually recommended in my previous
post.
 
L

lavu

Nicholas,

Thanku for your efforts. I am hoping you can help me with some
suggestions based on the scenario that I will explain below:

I have a COM dll from which I can instantiate an object of type Class A
in my client.
I have a webservice from which I can instantiate an object of type
Class B in my client.
I need to have a common reference to either object which will be done
at run-time. I do not have access to the actual DLL or the webservice.
How can I use an interface to implement this ?
 

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