Class Library with Service Links

I have a class library (.NET) with a link to a web service (on some server, not on a project in the same solution). The class library has a class that is exposed to COM. This class calls the web service.

When I add a link to the service, this adds the code to the app.config class library.

I also have a desktop application in the same solution, just for testing purposes. When I run this application, it throws this exception:

Could not find the default endpoint element that refers to the ServiceProxy.EventsServices contracted service in the ServiceModel client configuration section. Perhaps this is due to the fact that the configuration file was not found for your application, or because the leaf element corresponding to this contract was not found in the client element.

This exception can be resolved by copying and pasting the generated code for the service link in the app.config class library into the desktop configuration file.

When deploying, I should only deploy the DLL (built from the class library), not the desktop application. I need to include a service link in a configuration file that can be read in a DLL.

Any suggestions?

Thanks!

+7
web-services class-library app-config
source share
3 answers

When you add a link to a service, Visual Studio creates a proxy server for you that reads the app.config file for the service URL.

You have the option to specify a static URL that does not use a configuration file.

If you want to get complicated and provide a dynamic URL without app.config parameters, you can copy this generated code and modify it to use a different type of source for configuration data (for example, such parameters) and this way you can deploy only DLLs.

The generated code is hidden in the code behind the service link. To see the code, you need to activate the "show all files" option for Solution Explorer and look for the Refecence.cs (or .vb) file in the Reference.map file.

This code should not be changed directly, but not copy the code, and then create a new class inside your structure. (and remove the original link)

Note that if you change the service (or Wsdl), you must manually change the class.

+6
source share

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

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

+2
source share

Thank you for the quick answer =). I will take into account.

I just switched from Service Reference to Web Reference. This eliminates the need to have configuration information in the client (which in my case is a Delphi desktop application), and indeed, I have no idea how to do this = P.

Using a web link, instead of the Service Reference, this link will be stored in the class library. According to David, it is used by the proxy server and cannot be changed from the configuration file, because the DLL does not (as John says).

Currently my solution would be to use a web link. I assume that I will have to encode some mechanism to make it customizable from a file.

Again, thank you both!

+2
source share

All Articles