views:

513

answers:

3

Hi!

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!

+2  A: 

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.

David Lay
What does reference.cs have to do with his question, and why are you talking about modifying it? I think you should edit your question to remove that part.
John Saunders
Because bloparod does not want to use the config, it's exposing the service to COM. It needs to modify the proxy's dependency on the config.
David Lay
But none of that is in reference.cs.
John Saunders
yes, the constructor of the proxy has that references, it's only the URL. Unless you provide static URL. if you do that, you don't need config file anyway.
David Lay
A: 

All use of the .NET configuration API gets configuration from the configuration file of the application. There's no such thing as a DLL configuration file - the app.config you see in your class library is just showing you what you'll need to copy.

Now, if you can only deploy the assembly, then your assembly will need to configure itself in code.

John Saunders
+1  A: 

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!

bloparod