Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web reference configuration issue

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.

like image 249
Steven Avatar asked Sep 27 '12 15:09

Steven


People also ask

What is a Web reference?

A Web reference enables a project to consume one or more XML Web services. Use the Add Web Reference Dialog Box to search for Web services locally, on a local area network, or on the Internet. After adding a Web reference to your current project, you can call any methods exposed by the Web service.

Where is Web config configuration file?

The Web. Config file is used to configure Oracle Web Application functionality. This file is typically installed in the c:\Inetput\wwwroot\WebApp directory.

What is the web config file used for?

A web. config file is a Windows file that lets you customize the way your site or a specific directory on your site behaves. For example, if you place a web. config file in your root directory, it will affect your entire site (www.coolexample.com).

How do you add a reference to a website?

To add a Web Reference You can also open the Add Web Reference dialog box in the Solution Explorer pane by right-clicking References and selecting Add Web Reference. In the Web reference name box, rename the Web reference toExcelWebService. Click Add Reference to add a Web reference for the target Web service.


1 Answers

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>
like image 129
Steven Avatar answered Nov 07 '22 06:11

Steven