WCF通过$ .getJSON返回语法错误

时间:2015-11-14 13:36:57

标签: javascript jquery json ajax wcf

好的,所以出于某种原因,我的网站很好,但我需要再次发布一些新内容。

现在我有一个活动页面在线工作正常,但在我的本地主机上它不再有效。我在WCF服务中调用GetEvents方法时只得到语法错误意外标记<

这就是我服务中的内容

public class EventData
{
  public DateTime? Date { get; set; }
  public DateTime? EDate { get; set; }
  public string Title { get; set; }
  public string Description { get; set; }
  public string Url { get; set; }
  public string Showlink { get; set; }
  public int Id { get; set; }
  public string Status { get; set; }
  public List<IdAndValue> GroupList { get; set; }
  public bool? Private { get; set; }
  public int Numbers { get; set; }
}

[OperationContract]
[WebGet]
public List<EventData> GetEvents()
{
  var user = HttpContext.Current.User;
  var userId = user.Identity.GetUserId();
  using (var ctx = new afraEntities())
  {
    if (!string.IsNullOrEmpty(userId))
    {
      var evnts = (from ue in ctx.UserEvents
        where ue.enddate >= DateTime.Now
        && (ue.privateEvent == null || ue.privateEvent == false
        ||
        ue.privateEvent == true &&
        ue.UserDetail.AspNetUser.AspNetUserRoles.Select(x => x.UserId).ToList().Contains(userId))
        select new EventData
        {
          Id = ue.Id,
          Date = ue.startdate,
          Description = ue.description,
          Showlink = "",
          Title = ue.title,
          Url = ue.www,
          Private = ue.privateEvent ?? false
        }).ToList();
    }
  }
  return evnts;

}

这是我的javascript

    $(document).ready(function () {
    var filePath = "/AFRAService/GetEvents";
    $.getJSON(filePath, function (data) {
    }).fail(function (xhr, ajaxOptions, thrownError) {
        alert(thrownError);
        alert(xhr.responseText);
    }).done(function (data) {
        var eventList = $("<div class=\"list-group\"/>");
        $.each(data.d, function (key, val) {
            var listgroupitem = $("<a href=\"#\" class=\"list-group-item\" />");
            var heading = $("<h4 class=\"list-group-item-heading\"></h4>").text(val.Title);
            listgroupitem.append(heading);
            var desc = $("<p class=\"list-group-item-text\"></p>").text(val.Description);
            listgroupitem.append(desc)
            eventList.append(listgroupitem);
        });
        $("#eventInfo").append(eventList);


        $.getJSON("/AFRAService/IsAdmin", function (userdata) {
            if (userdata) {
                $(".sysadmin").show();
                $(".eventdelete").click(function () {
                    var json = { id: $(this).data("value") };
                    bootbox.confirm("Are you sure?", function (result) {
                        if (result) {
                            $.ajax({
                                method: "POST",
                                dataType: "json",
                                url: "/AFRAService/DeleteEvent",
                                contentType: "application/json; charset=utf-8",
                                data: JSON.stringify(json),
                                processData: true,
                                success: function () {
                                    window.location.reload();
                                }
                            });
                        }
                    });
                });
            } else {
                $(".sysadmin").hide();
            }
        });
    });
});

在我的服务顶部我

[ServiceContract(Namespace = "", SessionMode = SessionMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

这是我的web.config服务部分

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
    </webHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="afra15.AFRAServiceAspNetAjaxBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="AFRABehaviour">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="afra15.AFRAService" behaviorConfiguration="AFRABehaviour">
      <endpoint address="" behaviorConfiguration="afra15.AFRAServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="afra15.AFRAService" />
    </service>
  </services>
  <standardEndpoints>
    <webHttpEndpoint>
      <standardEndpoint crossDomainScriptAccessEnabled="true" maxBufferPoolSize="524288" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
    </webHttpEndpoint>
  </standardEndpoints>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

0 个答案:

没有答案