Web Services .net framework 2
I have just ported an ASP.NET 1.1 application to framework version 2 and i have a problem.
My solution has a Web project and a class library project. The class library project has a web reference to a web service. The Web project makes a call to the web service.
I used to hold the url for the web service in the web.config and because the web reference was set to dynamic, this all used to work fine.
Now it looks a though the class library project has a config file with the url in. My question is how do I change the path of the url after the project has been deployed to the web server? I Can't find any config files.
Putting the value in web.config does no longer work.
Any help will be appreciated.
Dave Bates
Hi,
The Webservice object has a property called Url. You can retrieve the Url of the WebService from the web.config file and assign it manually in the class library - assigning it should surely work.
MyWebService obj = new MyWebService();
obj.Url = ConfigurationManager.AppSettings["MyUrl"]; Regards,
Vikram
Hi,
In this situation you can go for a Wrapper Class and Wrap each method of the webservice with same methods on the wrapper. Within the methods u call the original methods. I have illustrated the concept with a code snippet below.
public class MyWebServiceWrapper
{
private MyWebService obj = new MyWebService();
public MyWebServiceWrapper()
{
obj.Url = ConfigurationManager.AppSettings["MyUrl"];
}
public void WebMethodA()
{
obj.WebMethodA();
}
}
Now, in your code, use just the wrapper class and call the methods.
Regards,
Vikram
A couple of questions:
1). In your example is the web service local?
2). In order to access a web service in VS 2K5 you have to add a "web reference". Is there a way to update the references URL at runtime?
Hi,
1.) The web service need not be local. You need it be accessible when you add a Web Reference thats all.
2.) Thats what has been shown. You would save the URL in the web.config file and then assign it to the .Url property of the WebService object at runtime in code.
Regards,
Vikram
Hi,
You will need to add a reference to System.Configuration.dll and then add an Imports directive to System.Configuration.
Then you would use the ConfigurationManager class to retrieve the stored setting:
| | objWebService.Url = ConfigurationManager.AppSettings["WebServiceUrl"] |
Regards,
Vikram
I managed to get access to the configuration manager. I still can't seem to get access to any application settings.
Here is part of my "app.config" file:
<applicationSettings>
<WebServiceTest.Settings>
<setting name="WebServiceTest_GetPrinters_ServiceRequestHandler"
serializeAs="String">
<value>http://someBox/ServiceRequestHandler/handler.asmx</value>
</setting>
</WebServiceTest.Settings>
</applicationSettings>
When I use the following code:
Dim test As Integer = ConfigurationManager.AppSettings.Count
I get a return of 0 everytime.