I come across this problem when i am writing an event handler in SharePoint. My event handler has a web reference. When i create this web reference, the URL of the web service will be added in the .config file of the assembly. If i have to change the web reference URL i just have to change the link in the config file.
Problem comes when I try to GAC the dll. When i GAC the DLL, the config file cannot be GACed along with the dll, and hence, there is no way for me to update the web reference.
One workaround i have found is to modify the constructor method Reference.cs class which is autogenerated by visual studio when i add a reference, so that the constructor reads the web service url from some other location, say a registry or an XML file in some predetermined location. But this poses a problem sometimes, as when i update the web referenc using visual studio, this Reference.cs file gets regenerated, and all my modifications would be lost.
Is there a better way to solve this problem?
If you have Visual Studio 2008, use a Service Reference instead of a Web Reference, which will generate partial classes that you can use to override functionality without your code overwritten by the generator.
For Visual Studio 2005, you could just add the partial keyword to the class in Reference.cs and keep a separate file with your own partial class: