如何在asmx文件中添加WebMethod [英] How to add WebMethod in an asmx file

查看:183
本文介绍了如何在asmx文件中添加WebMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在ASPX Web项目中工作,该项目已经有一个asmx文件.它包含大约4种WebMethod,这4种Web方法显示了http://localhost:2133/WebServices.asmx

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

现在,我尝试添加名为 GetCities 新WebMethod ,该方法与现有方法非常相似,但是未在http://localhost:2133/WebServices.asmx中显示该列表.我尝试重新编译它.当我深入检查(服务引用)时,找不到在何处引用WebService 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.

现有方法

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

        }
    }

我添加的新方法

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

        }
    }

完全困惑,请分享您的想法.

Totally confused, please share your thoughts.

推荐答案

您需要通过执行以下操作来更新用于与Web服务一起使用的代理类:

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

  1. 在解决方案资源管理器中,打开项目的App_WebReferences文件夹,然后单击要更新的Web参考的节点.
  2. 右键单击引用,然后单击更新Web引用". XML Web服务的新文件已下载到您的项目中. XML Web服务的信息将在您的项目中更新.
  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.

阅读如何:更新项目网站参考以获取文档.

这篇关于如何在asmx文件中添加WebMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆