如何解决服务器方法“ xxx”失败
| 我有这个工作,现在却没有。我们有多个开发人员在从事该项目,但是代码看起来像是在我工作时一样。我在另一篇文章中提到过一点,URL重写可能会引起问题,但是如果这是问题所在或有针对此问题的修复程序,它就不会出现。遗憾的是,这是一个网站(不是Web App),但是可以正常工作。另一个可能的问题是我们正在使用Ektron CMS。再次,它与所有这些变量一起使用,除了URL的别名/重写之外,因此这可能是问题所在。 javascript端在intellisense中看到了该方法。我什至有警报向我显示该方法,因此它知道该方法在那儿。但是我收到消息:服务器方法'LookupCourseItems \'失败。<script language=\"javascript\" type=\"text/javascript\">
function CourseLookup(ItemLookup,ResultID) {
alert(\'Attempting to look up: \' + ItemLookup);
var service = new AjaxDataServices.AjaxService();
service.LookupCourseItems(ItemLookup,onCourseLookupSuccess,onCourseLookupFailure,ResultID);
} // CourseLookup - Method
function onCourseLookupSuccess(result,userContext) {
var o = document.getElementById(userContext);
if (o != null) {
alert(\'Success!\');
o.outerHTML = result;
} else {
alert(\'Unable to find: \' + userContext);
} // if we were able to find the element to fill
} // onCourseLookupSuccess - Method
function onCourseLookupFailure(result) {
alert(result.get_message());
alert(\"StackTrace: \" + result.get_stackTrace());
alert(\"StatusCode: \" + result.get_statusCode());
alert(\"ErrorObject: \" + result.get_errorObject());
} // onCourseLookupFailure - Method
这是ScriptManager:
<asp:ScriptManager ID=\"ScriptManager\" runat=\"server\">
<Services>
<asp:ServiceReference Path=\"~/AjaxService.svc\" />
</Services>
</asp:ScriptManager>
这是服务:
[ServiceContract(Namespace = \"AjaxDataServices\")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AjaxService {
[OperationContract]
public string LookupCourseItems(string LookupPair) {
CourseRepository Repository = new CourseRepository(ConfigurationManager.ConnectionStrings[\"CAMS\"].ConnectionString,7);
string CourseID = \"\";
string SemesterName = \"\";
if (LookupPair.Contains(\":\")) {
string[] Parts = LookupPair.Split(new char[] { \':\' },StringSplitOptions.RemoveEmptyEntries);
CourseID = Parts[0];
SemesterName = Parts[1];
} else {
CourseID = LookupPair;
} // if the Semester was also given
Course Item = Repository.GetSingleCourseInformation(CourseID,SemesterName);
if (string.IsNullOrWhiteSpace(SemesterName))
return Item.ToHTML();
else
return Item.Semesters.Where(s => s.Name == SemesterName).SingleOrDefault().ToHTML();
} // LookupCourseItems - Method
运行时,初始的“尝试查找:1234”有效。
然后,将调用onCourseLookupFailure方法,并对本文标题中的消息进行处理。
然后StackTrace为空
StatusCode是404
并且ErrorObject为null。
404让我觉得它找不到服务。这似乎也是合乎逻辑的,因为当我在服务器端进行调试时,它永远不会到达Web服务。
有什么建议或想法吗?
解决方法
我建议使用一个名为“ Fiddler”的工具,它是一个HTTP调试代理,可让您查看来自客户端/服务器的HTTP请求。
它可以帮助您诊断您的请求正在发生什么。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。