Question

I am struggling with how to configure the url to a web reference.

Here is the case. I have: old asp.net webservices <----- c# project that compiles to dll <----- website that references the dll (the c# project didn't used to be there but I refactored all that code into a seperate project)

So the website code calls the c# project's code to get results which in turn calls the webservice.

When adding a web reference in the c# project I entered the url location of the webservices (http://192.168.10.1/TestServices.asmx?wsdl. This then generates an app.config file containing the url of the webservices.

If I set the web reference to static than the config should not be used, that is working. Now if I set the web reference to dynamic, the config should be used but since this is a project being compiled to a dll, and the website does not have the app.config, instead I set the configuration from the app.config to my web.config appSettings node and I changed the url to the web services to another one (http://192.168.10.2/TestServices.asmx.

The website is still getting the result from the old url to which the web reference was pointed when adding it in the c# project so it looks like the config setting is not being used while the URL Behavious is set to Dynamic.

Am I missing something trivial here, probably?

This is the content from the app.config:

<applicationSettings>
     <XXXX.Properties.Settings>
      <setting name="XXXX_TestServices_TestServices" serializeAs="String">
       <value>http://192.168.10.1/TestServices.asmx</value>
      </setting>
     </XXXX.Properties.Settings>
    </applicationSettings>

This is what I put in my web.config:

<appSettings>
     <add key="XXXX_TestServices_TestServices" value="http://192.168.10.2/TestServices.asmx" />
</appSettings>

So, now its always funny and informative/educational when during the typing of the question and double checking and search related question, you finally solve the question yourself.. I am posting it anyway with answer as I did not find the exact answer in one place but by combining 2 other questions and a blog post.

Was it helpful?

Solution

Some resources mention you need to create a setting and need to change the url property of the web service proxy object in your code. That is not necessary, you only need to edit your web config in the right way.

The url does not go in the appSettings section of your web.config as would be when referencing a web service directly from the website.

Instead you need to copy the entire config code from the generated app.config from your dll project, including the sectiongroup configuration that defines the applicationSettings node used for setting the correct url.

For this specific example that included the following config code in the web.config:

<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="XXXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
...
</configuration>

<applicationSettings>
    <XXXX.Properties.Settings>
      <setting name="XXXX_TestServices_TestServices" serializeAs="String">
        <value>http://192.168.10.2/TestServices.asmx</value>
      </setting>
    </XXXX.Properties.Settings>
</applicationSettings>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top