views:

222

answers:

2

I have a MOSS 2007 Webpart that displays data obtained from an external webservice (not originating from sharepoint).

It's created using VS2009, the webpart project includes a WebReference to my WebService and it uses the following code to make a connection (the url is configured in the WebReference):

    //get xml sitemap from webservice
    MenuService.MenuService service = new MenuService.MenuService();
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    XmlNode sitemapRootNode = service.GetSiteMapXML();

I compiled the webpart, deployed it in the BIN folder, everything works fine.

However I cannot change the web service URL... If I want to move the webpart to another environment, I need to recompile the whole thing in order to change the webservice URL

Also, when I compile the webpart projects it creates a webpartname.dll.config file that contains the URL to the webservice... however this config files does nothing. If I change it, or simply delete it from the BIN folder, the webpart still connects to the old URL... URL seems to be hardcoded in the webpart DLL.

Is there a way to configure a webpart so it will look in a config file for its webservice URL?

+2  A: 

The web part runs as a part of the site. It should take these configurations from the site's web.config, so try inserting the configurations from webpartname.dll.config to web.config file (this takes a little though to maintain the same sections, but isn't complicated).

Kobi
Why didn't I think of that... Thanks!
scoob
+2  A: 

There's also SPConfigStore. This is an appropriate solution if there are several servers in the farm and you wish to maintain the web service URL in a central location, stored in the SharePoint database.

Alex Angas