我想我会先进入一个简单的教程,然后继续创建一个网络服务。
我让webservice工作,所以现在我想将数据添加到我的数据库。但是,当我查看我的预览表单时,我找不到我的InsertComment
无效。
这是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
namespace MyFirstWebService
{
/// <summary>
/// Summary description for Math
/// </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 Math : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public int Add(int a, int b)
{
return (a + b);
}
[WebMethod]
public System.Single Subtract(System.Single A, System.Single B)
{
return (A - B);
}
[WebMethod]
public System.Single Multiply(System.Single A, System.Single B)
{
return A * B;
}
[WebMethod]
public System.Single Divide(System.Single A, System.Single B)
{
if (B == 0)
return -1;
return Convert.ToSingle(A / B);
}
[WebMethod]
public static void InsertComment(string value)
{
SqlParameter sqlParameter = new SqlParameter();
sqlParameter.ParameterName = "NewComment";
sqlParameter.Value = value;
List<SqlParameter> sqlParam = new List<SqlParameter>();
sqlParam.Add(sqlParameter);
SQLOperations.executeStoredProcedure("InsertNewComment", sqlParam);
}
}
}
任何有关InserComment方法无法使用的帮助都会很棒!
谢谢!
答案 0 :(得分:0)
因为它是静态功能。请在下面的帖子中查看此问题和答案
Why are Static Methods not Usable as Web Service Operations in ASMX Web Services?