繁体   English   中英

如何在C#(ASP.NET 2.0)中将值从一个类返回到另一个

[英]How to return a value from one class to another in C# (ASP.NET 2.0)

我有一个带有代码的类(简体):

namespace CustomerData
{
    public class InsertCustomer
    {
    public string name { get; set; }
        public string customerID { get; set; }

    public string Add()
    {
        //Insert into a database

        //Condition to check if the insert was successfull
        if (successful)
        {
            return id;
        }
        else
        {
            //If the insert was not successfull
        }
    }


    }
}

现在,我想以与上述类相同的解决方案(简化代码)将此值传递给我的Web服务(ASP.NET 2.0):

namespace CustomerData
{
    [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService] 

    [WebMethod]
        public string deleteCustomer(string customerID)
        {
            return customerID;
        }

然后本质上,我想要一个AJAX GET函数来获取此ID并使用此变量执行一个函数,但是如果我可以将值获取到WebMethod中,那么我认为我会从中受益的。

关于如何执行主题描述的任何建议? 提前致谢。

您是否考虑过从InsertCustomer类调用Web方法?

    CustomWebService srv  = new CustomWebService;
    srv.deleteCustomer(returnedCustomerID);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM