I have a class library (.NET) with a reference to a web service (in some server, not a project in the same solution). The class library has a class that is exposed to COM. This class invokes the web service.
When I add the service reference, this adds code to the class library's app.config.
I also have a desktop application in the same solution, just for test purposes. When I run this application, it throws this exception:
Could not find default endpoint element that references contract 'ServiceProxy.EventsServices' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
This exception can be solved by copying and pasting the generated code for the service reference in the class library's app.config into the desktop application' config file.
When I deploy, I have to deploy only the DLL (built from the class library) and not the desktop app. I need to include the service reference in a config file that can be read by the DLL.
Any suggestions?
Thanks!
Thank you both for the quick answers =). I'll take'em into account.
I have just changed from Service Reference to Web Reference. This removes the need to have config info in the client (that in my case is a Delphi desktop app), and really, I have no idea how to do it =P.
Using a Web Reference instead a Service Reference produces the reference to be kept into the class library. As David says, it's used by the proxy, and cannot be changed from a config file because a DLL hasn't got one (as John says).
By now, my solution will be to use a Web Reference. I guess that I'll have to code some mechanism to make it configurable from a file.
Again, thanks to both of you!
When you add a service reference, Visual Studio generates a proxy for you, which reads the app.config file for the url of the service.
You have the option to provide static URL wich does not uses the config file.
If you want to get complicated, and provide dynamic URL without the app.config settings, you could copy this generated code and modify it to use another kind of source for the configuration data (like parameters, for example) and that way you can deploy just the dll.
The generated code is hidden in the code behind of the service reference. In order to see the code, you have to activate the "show all files" option for the solution explorer, and look for the file Refecence.cs (or .vb) under Reference.map file.
This code you should not modify directly, instead, copy the code and then create a new class within your structure. (and delete the original reference)
Take notice, that if you modify the service (or the Wsdl) then you must modify the class manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With