所以我有一些问题。问题的目标是,当我尝试从用户控件和Ajax调用Web服务时,我得到了500个内部服务器错误。ASP.NET - 从用户控件(.Ascx)调用Web服务返回错误500内部服务器错误
还有就是我的代码示例:
Web服务.CS
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BudgetJson : System.Web.Services.WebService {
public BudgetJson()
{
}
[WebMethod]
public static String GetRecordJson()
{
return " Hello Master, I'm Json Data ";
}
}
用户控件(.ascx)文件(AJAX调用)
$(document).ready(function() {
$.ajax({
type: "POST",
url: "BudgetJson.asmx",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg)
{
alert(msg);
}
});
});
所以,当页面加载和要求我得到了这样的回应:
soap:ReceiverSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() at System.Xml.XmlReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) --- End of inner exception stack trace ---
如果我会添加方法名的网址,我得到了这样的错误:
Unknown web method GetRecordJson. Parameter name: methodName 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.ArgumentException: Unknown web method GetRecordJson. Parameter name: methodName
任何解决方案?
仍然是同样的错误... – 2011-12-13 18:00:58