无法自动调试Web服务(ASMX)

时间:2018-06-15 07:03:14

标签: c# asp.net web-services web asmx

我是网络服务新手。 我有Calculator WebService,我在Asp.net WebForms中使用它,但问题是当我将CacheDuration = 50添加到Web服务的方法时,我开始出错。

  

无法自动调试Web服务。无法调试远程过程。

当我在WebForm中添加2次相同的数字3次时出现此错误

我已经

<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
在WebService和WebApplication中都有

,我已经从控制面板修复了Visual Studio Community 2017,但是这些都不起作用,我仍然会收到此错误。

网络服务代码:

 /// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Calculator : System.Web.Services.WebService
{

    [WebMethod(EnableSession = true, Description = "this adds two integers", CacheDuration = 50)]
    public int Add(int firstNumber, int secondNumber)
    {
        int result = firstNumber + secondNumber;
        List<string> calculations = new List<string>();
        if (Session["Calculations"] == null)
        {
            calculations.Add(firstNumber.ToString() + " + " + secondNumber.ToString() + " = " + result.ToString());
            Session["Calculations"] = calculations;
        }
        else
        {
            calculations = (List<string>)Session["Calculations"];
            calculations.Add(firstNumber.ToString() + " + " + secondNumber.ToString() + " = " + result.ToString());
            Session["Calculations"] = calculations;
        }
        return result;
    }

    [WebMethod(EnableSession = true)]
    public List<string> GetRecentCalculations()
    {
        if(Session["Calculations"] == null)
        {
            List<string> calculations = new List<string>()
            {
                "You did not perform any calculations"
            };
            return calculations;
        }
        else
        {
            return (List<string>)Session["Calculations"];
        }
    }
}

WebForm代码

public partial class CalculatorWeb : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            CalculatorService.CalculatorSoapClient client = new CalculatorService.CalculatorSoapClient();
            GridView1.DataSource = client.GetRecentCalculations();
            GridView1.DataBind();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        CalculatorService.CalculatorSoapClient client = new CalculatorService.CalculatorSoapClient();
        lblResult.Text = client.Add(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString();
        GridView1.DataSource = client.GetRecentCalculations();
        GridView1.DataBind();
    }
}

0 个答案:

没有答案