为什么在AJAX自动完成扩展程序中没有调用WCF服务?

时间:2013-08-06 03:15:05

标签: c# asp.net wcf asp.net-ajax

我正在尝试在自动完成扩展程序中使用wcf服务,但它没有被调用但是我在Web服务中尝试过的相同的东西它在那里正常工作。

以下是我的示例代码

在App_Code / AutoCompleteWCF.cs

 [ServiceContract]
    public interface IAutoCompleteWCF
    {
        [OperationContract]    
        [System.ServiceModel.Web.WebInvoke(Method = "POST",ResponseFormat =  System.ServiceModel.Web.WebMessageFormat.Json)]
        string[] GetCompletionList(string prefixText, int count );
    }

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AutoCompleteWCF : IAutoCompleteWCF
    {
        [OperationContract]
        [System.ServiceModel.Web.WebInvoke(Method = "POST", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json)]        
        public string[] GetCompletionList(string prefixText, int count)
        {
            string[] str = new string[5];

            str[0] = prefixText + "A";
            str[1] = prefixText + "B";
            str[2] = prefixText + "C";
            str[3] = prefixText + "D";
            str[4] = prefixText + "E";

            return str;

        }
    }

AutoCompleteWCF.svc

 <%@ ServiceHost Language="C#"Debug="true" Service="AutoCompleteWCF" CodeBehind="~/App_Code/AutoCompleteWCF.cs" %>

Web.confifg

  <?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <services>
      <service name="AutoComplete" behaviorConfiguration="ServiceBehavior">
        <endpoint address="F" binding="webHttpBinding" contract="IAutoCompleteWCF" behaviorConfiguration="ServiceAspNetAjaxBehavior">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
      </service>
    </services>

  </system.serviceModel>

</configuration>

WebForm1.aspx的

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AutoCompleteDemo.WebForm1" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ccl" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ccl:ToolkitScriptManager ID="ScriptManager1" runat="server"></ccl:ToolkitScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ccl:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
                BehaviorID="AutoCompleteEx"
                TargetControlID="TextBox1"
                ServicePath="AutoCompleteWCF.svc" 
                ServiceMethod="GetCompletionList"
                MinimumPrefixLength="2" 
                CompletionInterval="1000"
                EnableCaching="false">
        </ccl:AutoCompleteExtender>
    </div>
    </form>
</body>
</html>

0 个答案:

没有答案