views:

718

answers:

3

Hi,

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.

Thanks,

Chris

+1  A: 

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
+1  A: 

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