问题
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:
- In Solution Explorer, open your project's App_WebReferences folder and click the node for the Web reference you want to update.
- 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