vendredi 15 juin 2018

Unable to automatically debug web service (ASMX)

I am new to web services. I have Calculator WebService , and I consume it in Asp.net WebForms but the problem is when I add CacheDuration = 50 to methods of web service, i start to get error .

Unable to automatically debug web service. The remote procedure couldn't be debugged.

and I get this error when I add 2 same numbers 3 times in WebForm

I already have

<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>

in both WebService and WebApplication and I have repaired Visual Studio Community 2017 from Control Panel but these don't work, I still get this error.

Code of Web Service:

 /// </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"];
        }
    }
}

Code of 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();
    }
}




Aucun commentaire:

Enregistrer un commentaire