Adding a web link to a dll that is gaced

I encounter this problem when I write an event handler in SharePoint. My event handler has a web link. When I create this web link, the web service URL will be added to the assembly's .config file. If I need to change the URL of a web link, I just need to change the link in the configuration file.

The problem occurs when I try to use the GAC dll. When I have a GAC ​​DLL, the configuration file cannot be GACed with the dll, and therefore, I have no way to update the web link.

One workaround I found is to change the reference.cs constructor method that the visual studio auto-generates when the link is added, so that the constructor reads the web service URL from some other place, for example, a registry or XML file in a specific location. But sometimes this creates a problem, because when I update a web link using visual studio, this Reference.cs file is restored and all my changes will be lost.

Is there a better way to solve this problem?

+4
source share
4 answers

If you have Visual Studio 2008, use a service link instead of a web link, which will generate partial classes that you can use to override functions without code overwritten by the generator.

For Visual Studio 2005, you can simply add the partial keyword to the class in Reference.cs and save a separate file with your own partial class:

public partial class WebServiceReference { public WebServiceReference(ExampleConfigurationClass config) { /* ... */ } } WebServiceReference svc = new WebServiceReference(myConfig); 
+1
source

Any application hosted by SharePoint uses the web.config located at the root of your SharePoint website in IIS. What you need to do is add the configuration generated by the Web / Service Link Wizard to your web.config.

This is roughly how it works:

  • SharePoint application pool loads your DLL
  • Your DLL looks for service information in the current application configuration file
  • Your DLL finds web.config and looks for configuration information there.

Basically, the app.config that is created in your DLL is not used. In this case, the application pool (w3wp.exe), which hosts the SharePoint application, is used as the application. For SharePoint, app.config is actually called web.config and exists at the root of the SharePoint site.

+2
source

I resolved this by making the web link dynamics for my class library and then copying the Settings section of the Settings application containing the web link from the app.config file to my Sharepoint web.config site.

Note that you will also need to copy the entry for the application settings into your web.config, since this usually does not happen.

0
source

You can try this: instead of using a dynamic web link, make it a static link so that the code in Reference.cs does not look up the value in the .config file for the URL. Then subclass the class generated web service client code and in this derived class add your own logic to set the .Url property. Then VS.NET can rename Reference.cs whatever he likes, and your URL setup code will remain. Of course, you need to update any downstream code to use the derived class, but it should be a simple global replacement.

-1
source

Source: https://habr.com/ru/post/1277101/


All Articles