我在我的项目中编写了一个用于提交表单的 Web 服务,但它不起作用。我用过 Umbraco CMS 6.1.5。
说明:
我在Master.master中写道:
<form id="AbniyehMainForm" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"
EnablePageMethods="true" ScriptMode="Auto">
<Services>
<asp:ServiceReference Path="~/Services/ApplicationFormService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Path="/scripts/building.js" />
</Scripts>
</asp:ScriptManager>
</form>
我在ApplicationFormService.asmx中写道:
[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 ApplicationFormService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string HelloWorld()
{
return "Hello World";
}
}
我在ApplicationFormControl.ascx.cs中写道:
[WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
public static void HelloWorld()
{
ApplicationFormService s = new ApplicationFormService();
s.HelloWorld();
}
我在default.aspx中写道:
<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="Defraz.Building.WebApp.Services" %>
<script runat="server" type="text/C#" language="c#">
[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static string HelloWorld()
{
return "HelloWorld!!!";
}
</script>
我在Building.js中写道:
function btnSendApplicationForm_onclick() {
PageMethods.HelloWorld(_onMethodComplete, _onMethodError);
}
function _onMethodComplete(result) {
alert(result.message);
}
function _onMethodError(result) {
alert(result._message);
}
当代码运行 PageMethods.HelloWorld(_onMethodComplete, _onMethodError) 时,我收到一个错误表单 _onMethodError 告诉我
“服务器方法‘HelloWorld’失败。”
请帮我。