服务器方法“xxx”;失败的

发布于 2024-11-01 18:17:19 字数 2789 浏览 0 评论 0原文

我曾经有这个工作,但现在不行了。我们有多个开发人员致力于该项目,但代码看起来就像我运行时一样。我在另一篇文章中看到,URL 重写可能会导致问题,但它从未讨论过这是否是问题所在,或者是否有解决方案。遗憾的是,这是一个网站(不是 Web 应用程序),但它正在运行。另一个可能的问题是我们使用 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为空 状态代码是 404 并且 ErrorObject 为空。

404让我觉得它找不到服务。这似乎也是合乎逻辑的,因为当我在服务器端调试时,它永远不会到达 Web 服务。

有什么建议或想法吗?

I had this working and now it is not. We have multiple developers working on the project but the code looks like when I had it working. I saw a slight mention in another post that URL rewriting may cause an issue but it never went into if that was the problem or if there was a fix for that. Sadly this is a Web Site (not Web App) but it WAS working. Another possible issue is that we are using Ektron CMS. Again, it was working with all of those variables, except the aliasing/rewriting of the URL, so this may be the issue.

The javascript side sees the method in intellisense. I even have an alert showing me the method so it knows its there. But I get the message: The server method 'LookupCourseItems' failed.

<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

Here is the ScriptManager:

<asp:ScriptManager ID="ScriptManager" runat="server">
  <Services>
    <asp:ServiceReference Path="~/AjaxService.svc" />
  </Services>
</asp:ScriptManager>

Here is the Service:

[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

When run, the initial "Attemping to look up: 1234" works.
Then the onCourseLookupFailure method gets called and ruteurns the message in the title of this article.
Then the StackTrace is empty
The StatusCode is 404
And the ErrorObject is null.

The 404 makes me think it can not find the service. This also seems logical since when I debug on the server side, it never gets to the Web Service.

Any suggestions or thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚你发端 2024-11-08 18:17:19

我建议使用一个名为“Fiddler”的工具,它是一个 HTTP 调试代理,使您能够查看 HTTP来自客户端/服务器的请求。

它可以帮助您诊断您的请求发生了什么情况。

I'd suggest using a tool called "Fiddler", it's a HTTP debugging proxy that will enable you to see the HTTP requests from the client / server.

It may help you diagnose what is happening to your requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文