Sunday, December 2, 2012

Dynamic URL of web service with web reference

It’s been a while I am writing this. But never late.. So I am writing this. Before some time one of friend asked about the URL of web service when we add reference. So I am writing this. Some of you may find this very basic but still many of people does not know this that’s why I am writing this.

In today’s world we have so many servers like development, preproduction and production etc. and for all the server location or URL of web service will be different.But with when you add a web reference to your web application it’s create a web reference settings in web.config where you can change this path. So it’s very easy to just change that path and you don’t have to add web reference again.

Let’s see how this work. For this I am creating a basic web service called hello world just like below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebApplication1
    [WebService(Namespace = "")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HelloWorld : System.Web.Services.WebService
        public string GetMessage()
            return "Hello World";

As you can see this is very basic and It’s return a “Hello World” string from GetMessage method. Now let’s add a web reference for this service to use this in page. To add a web reference we need to right click and click add web reference. It will load following dialog box for web reference.

Add web reference dynamic url of web service

Once you click web service in this solution It will load our helloworld web service.

Add web reference of hello world service dynamic url of web service

Once you click on “HelloWorld” it will add web reference.


Once you click “Add Reference” it will add web reference for the web service. Now after adding a web reference when you see web.config. It has created a new settings for it like below.

        <setting name="WebApplication1_localhost_HelloWorld" serializeAs="String">

Here you can see the URL of web service. So you can put any url of same web service. It’s very easy. Hope you like it. Stay tuned for more..Till then happy programming. 

Shout it

kick it on


Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews