How to add WebMethod in an asmx file

心已入冬 提交于 2019-12-12 17:51:52

问题


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

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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/18726521/how-to-add-webmethod-in-an-asmx-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!