我需要在我的客戶端頁面中用JavaScript調用我的Web服務方法。我想我沒有正確地引用這個正確的,並希望幫助搞清楚這一點,請。Asmx web服務引用問題
錯誤消息說「CalendarHandler未定義」。
<%@ WebService Language="C#" CodeBehind="~/App_Code/CalendarHandler.cs"
Class="CalendarHandler" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="CalendarPage.aspx.cs" Inherits="CalendarPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<input type="button" id="loadevents" onclick="callLoadEvents();" />
<div id="eventresults"> </div>
<div id="resultFailed"> </div>
<script language="javascript" type="text/javascript">
var tasks;
function callLoadEvents() {
Speak.CalendarHandler.GetEvents(GetLoadAddress_success, OnFailed);
}
function GetLoadAddress_success(e) {
tasks = e;
}
// --------------------------
function OnFailed() {
$get('resultFailed').innerHTML = "failed";
}
</script>
</asp:Content>
using System.Web;
using System.Web.Services;
[WebService(Namespace = "Speak")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[System.ComponentModel.ToolboxItem(false)]
public class CalendarHandler : System.Web.Services.WebService
{
static IDictionary<DateTime, String> Calendarevents;//hold my events in this
public CalendarHandler() {
Calendarevents = new Dictionary<DateTime, string>();
Calendarevents.Add(DateTime.Now, "Going to meeting with XYZ Company");
Calendarevents.Add(DateTime.Now.AddDays(1), "XML Class at 2pm");
Calendarevents.Add(DateTime.Now.AddDays(1),"ASP.NET 3.5 Ajax");
Calendarevents.Add(DateTime.Now.AddDays(1),"Pocket Guide");
Calendarevents.Add(DateTime.Now.AddDays(1),"Grocery Shopping");
}
[WebMethod]
public IDictionary<DateTime, String> GetEvents()
{
return Calendarevents;
}
}
您的幫助表示讚賞
我從主頁面scriptmanager中刪除了servicereference,而是像上面在子頁面中那樣使用了scriptmanagerproxy。我仍然無法使用我爲我的服務定義的名稱空間調用webservice方法。 – Kobojunkie 2011-06-12 01:36:26
我可以通過CalendarHandler.GetEvents(GetLoadAddress_success,OnFailed)調用我的引用;但不Speak.CalendarHandler.GetEvents(GetLoadAddress_success,OnFailed); – Kobojunkie 2011-06-12 01:37:40
用替代方法更新。 – 2011-06-12 01:58:54