【发布时间】:2013-02-28 16:40:14
【问题描述】:
我正在尝试使用 Web 服务返回 FullCallendar Resource 请求的资源的 json 列表:
这是网络服务类:
/// <summary>
/// Summary description for CalendarServices
/// </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 CalendarServices : System.Web.Services.WebService
{
public CalendarServices()
{
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetEmployees()
{
List<object> eventList = new List<object>();
var emps = ResourceManager.GetAllEmployees();
foreach (Employee e in emps)
{
eventList.Add(
new
{
id = e.EmployeID.ToString(),
name = e.EmployeName
}
);
}
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(eventList);
return strJSON;
}
}
这里是它的名字:
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
defaultView: 'resourceNextWeeks',
numberOfWeeks: 5,
weekends: false,
editable: true,
selectable: true,
minTime: 8,
maxTime: 16,
refetchResources: true,
selectHelper: true,
resources: 'CalendarServices.asmx/GetEmployees'
,
events: [
{
我不确定为什么这不起作用。也许我不懂网络服务?
在示例中,他们调用 resources.php,它只是回应它。
基本上我想要的是如果我去 CalendarServices.asmx/GetEmployees
我想在我的浏览器中看到这个:
[
{
"name":"Resource 2",
"id":"resource2"
},
{
"name":"Resource 1",
"id":"resource1"}
]
纯文本就可以了。目前,如果我在浏览器中尝试此 url,它会崩溃。
我能做什么?
谢谢
崩溃:
Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetEmployees'.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +489333
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +226
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +145
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
【问题讨论】:
-
该崩溃是否伴有行号以及可能暗示问题所在的错误消息?
-
ASMX 是一项遗留技术,不应用于新开发。 WCF 应该用于 Web 服务客户端和服务器的所有新开发。一个提示:微软已经在 MSDN 上停用了ASMX Forum。
-
您是否尝试取消注释它说应该取消注释以在 AJAX 调用中使用它的行?
标签: c# asp.net json web-services