我在我的项目中为提交表单编写了一个web服务,但它不起作用。我使用过Umbraco 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’失败”
请帮帮我。
发布于 2013-10-09 01:38:40
既然您使用的是v6.x,那么可以使用Umbraco实现吗?因此,与其创建webservice,不如创建一个WebAPI控制器/操作,如本文所示:http://our.umbraco.org/documentation/Reference/WebApi/
它的优点是您可以直接从控制器访问所有Umbraco上下文和服务。
显然,这意味着您不一定会得到webmethod
的好处,但是如果您返回json并将其反序列化为您可以使用的强类型,那么您仍然可以在其中完成大部分工作。
发布于 2013-10-09 00:28:13
WebMethods不能在用户控件中。我建议使用webservice (.asmx)并将您的and方法放在那里。
发布于 2013-10-14 22:50:43
我不认为你用Umbraco写了一个web服务,听起来你想和Umbraco一起定位一个。为什么不向现有的web服务添加一个服务引用?或者,将WebApi库包含在您的Umbraco解决方案中,并进行Restful调用。
https://stackoverflow.com/questions/19265714
复制