请教有个WebService的错误.非常危

2025-01-02 08:03:16
推荐回答(1个)
回答1:

简单的..做个简单的例子

WebService代码

public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public bool AddNewProduct(Product p)
{
//做想做的事,判断是否添加成功
bool state = false;
return state;
}
}
public class Product
{
public int ID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}

在远程引用此服务后,页面代码是:

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LocalWebService.WebService1SoapClient client = new LocalWebService.WebService1SoapClient();
LocalWebService.Product p = new LocalWebService.Product();
p.ID = 1;
p.Name = "测试产品";
p.Price = 100;
client.AddNewProduct(p);
}
}