代码之家  ›  专栏  ›  技术社区  ›  Howard Pinsley

如何获得WCF Ajax服务的智能感知?

  •  3
  • Howard Pinsley  · 技术社区  · 16 年前

    /// <reference path="JQuery\jquery-1.3.2.js"/>
    

        <asp:ScriptManager ID="ScriptManager1" runat="Server" EnablePartialRendering="false" AsyncPostBackTimeout="999999">
            <Services>
                <asp:ServiceReference path="../Services/DocLookups.svc" />
            </Services>
        </asp:ScriptManager>
    

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

    [ServiceContract(Namespace = "Documents.Services", Name = "DocLookups")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class DocLookups {
    ...
    

        //Called at the begining of the page to fill in the category list
        [OperationContract]
        public SelectOption[] GetCategoriesForSelectList()
        {
            SelectOption[] Result;
            IDocumentRepository repository = new DocumentEntityRepository(ConnectionString);
            Result = (from cat in repository.GetDocCategories()
                      select new SelectOption(cat.Category_ID.ToString(), cat.CategoryName)).ToArray();
            if (Result.Length > 0)
                Result[0].Selected = true;  //Select first item 
            return Result;
        }
    

    namespace Documents.Services {
    
    [DataContract]
    public class SelectOption
    {
        //A useful DTO to use when filling a <select> element with options
        public SelectOption(string optionValue, string optionText) {
            OptionValue = optionValue;
            OptionText = optionText;
            Selected = false;
        }
        public SelectOption(string optionValue, string optionText, bool selected) {
            OptionValue = optionValue;
            OptionText = optionText;
            Selected = selected;
        }
    
        [DataMember]
        public string OptionValue { get; set; }
        [DataMember]
        public string OptionText { get; set; }
        [DataMember]
        public bool Selected { get; set; }
    }
    

    }

    Documents.Services.DocLookups.GetCategoriesForSelectList(...
    

    假定的

    3 回复  |  直到 16 年前
        1
  •  4
  •   Scott Hanselman    16 年前

    /// <reference path="../Services/DocLookups.svc" />

        2
  •  0
  •   Howard Pinsley    16 年前

    ///<reference path... 
    

    线。我不知道它记录在哪里,但不知何故,我错过了WCF生成的客户端代理所必需的——尽管现在使用相同的习语来获取JQuery的Intellisense,这是有意义的。

    根据记录,考虑到我的项目结构,我最终不得不使用的行与斯科特建议的行略有不同。我试过:

    /// <reference path="../Documents/Services/DocLookups.svc" /> 
    

    然后我保存了文件,并从VS编辑菜单中选择 智能感知 ... 更新JScript智能感知 ...

    不幸的是,这不起作用,我在更新Intellisense时遇到了以下错误:

    Error updating JScript IntelliSense: 
    C:\TFSSource\LitigationPortal\Version 1.0\LitigationPortal\Documents\Services\DocLookups.svc:
    'Type' is undefined @ 0:0
    

    所以我取得了一些进展,但还没有完全达到。