0

I am writing a DLL in VB.NET which will be referenced by an ASP.NET website.

The DLL project has a reference to a web service in it. When I added the web service to the project, a chunk of configuration information was added to the 'app.config' file.

In order to get this to work in the host website, I had to copy the information in the 'app.config' file into the 'web.config' of the website.

Does anybody know how I can embed these settings into my compiled DLL? I don't want the consumers of my DLL to have to insert this settings block into their web.config files.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Chris Roberts
  • 18,622
  • 12
  • 60
  • 67

3 Answers3

4

The 'svc.Endpoint.Address' expects an object of type System.ServiceModel.EndpointAddress, so in fact what is required is on the lines of...

Dim address As New System.ServiceModel.EndpointAddress("http://Whatever")
Dim binding As New System.ServiceModel.BasicHttpBinding()

' The binding object is already set up with the default values normally found in the
' <bindings> section of the App.Config, but can be overriden here, eg...
binding.ReceiveTimeout = new System.TimeSpan(0,20,0)

Dim ws As New MyWebServiceSoapClient(binding, address)
FourOaks
  • 190
  • 1
  • 3
  • 7
1

Does anybody know how I can embed these settings into my compiled DLL? I don't want the consumers of my DLL to have to insert this settings block into their web.config file

Yes, you can set the address in code. On the generated proxy class, you have the Url property (for old-style asp.net webservices proxy) or the Endpoint.Address property (for WCF generated webservice proxy).

//MyWebService is a non-WCF generated proxy
MyWebService ws = new MyWebService();
ws.Url = "http://whatever/";

or

//MyWebServiceSoapClient is a WCF generated proxy
MyWebServiceSoapClient svc = new MyWebServiceSoapClient();
svc.Endpoint.Address = "http://whatever";

Though, this would probably mean hardcoding those values in your dll, and I wouldn't recommend that...

Arjan Einbu
  • 13,543
  • 2
  • 56
  • 59
0

Actually, copy and paste is the solution. This is how .NET has always worked. Configuration settings for any external (library) code must go into the config file for the "executing" application. This would be the application.exe.config file for a console or Windows Service application, or one of the web.config files for an ASP.NET, WCF or other web-based application.

See If app.config for a DLL should be in the “main config”… what do we do with WCF References in DLLs?.

The overall idea is that the library code that needs the settings may be used by multiple executing applications. In this case, the settings will be different for each application.

If your settings were in the DLL, then the consumers of your DLL would not be able to edit the settings.

If you have "settings" which are not permitted to ever change, then, as https://stackoverflow.com/a/686126/76337 and https://stackoverflow.com/a/655452/76337 have shown, you should configure things in code, not in an unconfigurable configuration file.

Community
  • 1
  • 1
John Saunders
  • 160,644
  • 26
  • 247
  • 397