Uncaught TypeError: undefined is not a function when ASP.NET client accesses the Service

Uncaught TypeError: undefined is not a function when ASP.NET client accesses the Service

我正在尝试创建一个 AJAX 启用的 WCF 服务和一个访问该服务的 ASP.NET 客户端。

我得到的错误是:

Uncaught TypeError: undefined is not a function

在这一行:

var service = new WcfService.Service1();

这是我的 asp.net 代码:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="GridView.aspx.cs" Inherits="ASPUserManager.Presentation.AspNetUI.GridView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Users GridView</title>
<link href="../Content/bootstrap.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../Scripts/jquery-1.9.0.js"></script>
<script type="text/javascript" src="../Scripts/knockout-3.3.0.js"></script>
<script type="text/javascript" src="https://rawgit.com/SteveSanderson/knockout.mapping/master/build/output/knockout.mapping-latest.debug.js"></script>
<script src="http://knockoutjs.com/examples/resources/knockout.simpleGrid.3.0.js"></script>
<%--<script type="text/javascript" src="../Scripts/clientServiceHelper.js"></script>--%>
</head>
<body>
<form id="form1" runat="server">

    <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>

    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        <services>
            <asp:ServiceReference Path="~/Service1.svc" />
        </services>
    </asp:ScriptManagerProxy>

 </form>

    <script>
        $(document).ready(function () {
            var service = new WcfService.Service1();
            service.GetAllUsers(onSuccess, null, null);

            function onSuccess(result) {
                alert(result);
            }
        });
    </script>

</body>
</html>

Service1.svc.cs

namespace WcfService
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {
        private ExceptionManager exManager;

        IApplicationService applicationService;

        public Service1()
        {
            this.applicationService = new ApplicationService();
        }

        #region Members

        public UsersDTO GetUser(UsersDTO userDTO)
        {
            return this.Process(() =>
            {
                return this.applicationService.GetUser(userDTO);
            });
        }

}

IService1.cs

namespace WcfService
{
    [ServiceContract(Namespace = "WcfService")]
    public interface IService1
    {
        [OperationContract]
        UsersDTO GetUser(UsersDTO userDTO);
    }
}

我希望我提供了所有必要的信息来分析这个问题。如果没有,请告诉我。如果有人可以帮助我,那就太好了。 我只是看不出可能是什么问题:)

您需要在调用 $(document).read

之前包含 jQuery 脚本
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            debugger;
            var service = new WcfService.Service1();
            //service.GetAllUsers(onSuccess, null, null);

            function onSuccess(result) {
                alert(result);
            }
        });
    </script>

正如 Cristina Alboni 所建议的,我尝试调试 javascript 代码,发现我试图以错误的方式初始化 wcf,而且我不得不更改 [=12] 中的一些配置=].