R – Web reference behavior in an ASP.NET web site project

asp.netweb services

On my local workstation, I have a Visual Studio studio that contains a .NET 3.5 C# class library project and an .NET 3.5 ASP.NET web site project.

I created a web reference (example http://prod.webservices/myservice/default.asmx) in the C# class library using the "Add Web Reference" module. It created an app.config with the following section:

<applicationSettings>
    <MyCompany.MyApp.Data.Properties.Settings>
        <setting name="MyCompany_MyApp_Data_MyWebService" serializeAs="String">
            <value>http://prod.webservices/myservice/default.asmx</value>
        </setting>
    </MyCompany.MyApp.Data.Properties.Settings>
</applicationSettings>

In my ASP.NET web propject I also created a reference to the same web service using the "Add Web Reference" feature. It added the following item to the appSettings of my web.config file:

<add key="MyWebService.default" value="http://prod.webservices/myservice/default.asmx" />

I also created a reference to the class library file in the ASP.NET web site project. When I deployed my ASP.NET web site to our development server, I only move the web.config file not the app.config file for the class library, and all reference to the web service work.

When I try to modify the web.config file to change the web reference to http://dev.webservices/myservice/default.asmx, it still uses the prod.webservice reference URL.

What do I have to do to get the development environment to use http://dev.webservice web service?

Best Answer

Explicitly assign the URL (by reading it from the config) after creating the proxy in your code.