开发者

The server method 'xxx' failed

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")]
[AspNet开发者_如何转开发CompatibilityRequirements(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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜