Praveen
Praveen

Reputation: 56509

How to add WebMethod in an asmx file

I have started working in ASPX web project, which has already an existing asmx file. It contains around 4 WebMethods and these 4 Webmethods are showing the http://localhost:2133/WebServices.asmx

enter image description here

Now I tried adding new WebMethod named GetCities very similar to the existing one, but it is not showing the list in http://localhost:2133/WebServices.asmx. I tried recompiling it. When I checked deeply (service reference)I couldn't find where the WebService WebServices.asmx is being referenced.

Existing Method

[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetAvailable(int clientCode)
    {
        try
        {
            //Db Querying statements
        }
        catch (Exception exc)
        {

        }
    }

New method I added

[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCities()
    {
        try
        {
           //Db Querying statements 
        }
        catch (Exception exc)
        {

        }
    }

Totally confused, please share your thoughts.

Upvotes: 3

Views: 5913

Answers (2)

mlurker
mlurker

Reputation: 149

When you start your project Visual Studio launches "ASP.NET Development Server" to host application. It is not always terminated once you close visual studio, so it may still execute older version of your web service. Try to stop this application or reboot your machine and see if it helps.

Upvotes: 0

Karl Anderson
Karl Anderson

Reputation: 34846

You need to update the proxy class that is used to work with your web service by doing the following:

  1. In Solution Explorer, open your project's App_WebReferences folder and click the node for the Web reference you want to update.
  2. Right-click the reference and click Update Web Reference. The new files for the XML Web service are downloaded to your project. Information for the XML Web service is updated within your project.

Read How to: Update a Project Web Reference for documentation.

Upvotes: 1

Related Questions