简体   繁体   中英

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

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

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 (ie specifying the address, binding, configuration etc through code to the constructors).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM