CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeffrey Palermo (.com)

Blog moved to www.jeffreypalermo.com

Deploying web service clients and web services without recompiling proxy class - level 200

There are a lot of people having issues when they have to change the location of the web service they are calling.  Some resort to recompiling the proxy class, but that isn't necessary.  The proxy class that is generated by VS hard-codes the URL of the web service in the class, but with a little foresight, you can avoid problems when the location of the web service changes.  First, let's create a configuration item to control the URL where the web service resides:

<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<appSettings>
<add key="webServiceUrl" value="http://localhost/service.asmx" />
</appSettings>
</
configuration>

Now, we just add 1 line to the code that calls this web service:

            myWebService.Batch service = new myWebService.Batch();

            service.Url = ConfigurationSettings.AppSettings["webServiceUrl"];

            Debug.WriteLine(service.Url);

            service.Credentials = System.Net.CredentialCache.DefaultCredentials;

            service.MyWebServiceMethod(textBox1.Text);

            Debug.WriteLine("Called web service");

By setting the “Url” property, we can change where the system goes to consume the web service.  Now, you can deploy the web service to any server, and if you change your app.config file, your client code won't miss a beat.



About Jeffrey Palermo

Jeffrey Palermo is a software management consultant and the CTO of Headspring Systems in Austin, TX. Jeffrey specializes in Agile coaching and helps companies double the productivity of software teams. Jeffrey is an MCSD.Net , Microsoft MVP, Certified Scrummaster, Austin .Net User Group leader, AgileAustin board member, INETA speaker, INETA Membership Mentor, Christian, husband, father, motorcyclist, Eagle Scout, U.S. Army Veteran, and Texas A&M University graduate. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With


This Blog

Syndication

News

Headspring Systems

View Jeffrey Palermo's profile on LinkedIn

See my new blog at .jeffreypalermo.com