Dynamic URL of asp.net 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 asp.net 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 = "http://dotnetjalps.com/")]
    [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 asp.net 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 DotNetKicks.com


Popular posts from this blog

How to create Rest API(Web API) with ASP.NET Core 1.0

Creating PDF with ASP.Net MVC and RazorPDF

Horizontal and vertical scrollbar in HTML5 and CSS3