Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF and moving the proxy code to a DLL. Is it possible?

Tags:

c#

proxy

wcf

it looks like I am not able to succesfully move my WCF proxy code into a separate DLL (as opposed to an EXE as I can see in all the examples I have run into).

The reason I am trying to do this is that I would like my proxy code to be invoked by different clients (possibly unmanaged code), which might not know anything about WCF but just need to access to the services (through a Facade exposed by the proxy maybe?).

Whenever I move the following code that creates a new proxy to a different VS project within the same solution, I get the dreaded "Could not find default endpoint element that references contract 'localhost.IRemoteCommandService' in the ServiceModel client configuration section" exception.

localhost.RemoteCommandServiceClient proxy = 
    new localhost.RemoteCommandServiceClient();

The same code works smoothly whenever used within a Main method in the same project where the proxy code is (auto-generated from Visual Studio).

Any idea? I hope that the client code of my proxy does not need to have the service model XML configuration as the proxy, because that would defeat the purpose I am moving the WCF proxy code into a DLL in the first place.

Thanks, Stefano

like image 762
Stefano Ricciardi Avatar asked Feb 01 '26 17:02

Stefano Ricciardi


2 Answers

The endpoints are indeed normally specified in the configuration file. You must look at the serviceModel data in the config file, and copy it into your calling app.config - or you need to use the more verbose way of creating the proxies in your code (i.e. specifying the address, binding, configuration etc through code to the constructors).

like image 162
Marc Gravell Avatar answered Feb 04 '26 07:02

Marc Gravell


If you don't want to have to endpoint configuration on the client, you'll have to embed it into your proxy dll by specifying everything in code.

Another option would be to use a dynamic proxy, like this one, which would allow you to not have the serviceModel in your client apps.

like image 33
Jason Cono Avatar answered Feb 04 '26 07:02

Jason Cono



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!