3

通过将补丁 KB958502 应用于 Visual Studio 2008 并包括以下行,我终于让 Intellisense 为 JQuery 工作:

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

在我的 .js 文件的顶部。现在我试图弄清楚如何为 ScriptManager 的 ScriptReference 元素生成的客户端代理获取 JavaScript 智能感知(如下所示):

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

客户端代理正在工作——即我可以通过它们拨打电话,但我没有得到智能感知。

我的服务是用 .svc 文件定义的:

<%@ 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; }
}

}

在我的 javascript 文件中,对该服务的调用如下所示:

Documents.Services.DocLookups.GetCategoriesForSelectList(...

但我没有得到 Intellisense(例如,如果我键入 Documents。没有弹出)。对于生成的方法或方法使用的 [DataContract] 类型,我都没有获得智能感知。

我相信我应该为这些代理和类型获得 Intellisense,但无法弄清楚我可能做错了什么。TIA。

4

3 回答 3

4

没有 /// <reference path="../Services/DocLookups.svc" /> 工作?

于 2009-02-26T06:01:54.800 回答
0

感谢 Scott 指出我需要添加

///<reference path... 

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

作为记录,我最终不得不使用的线路与斯科特根据我的项目结构提出的建议略有不同。我试过:

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

然后我保存了文件并从 VS Edit 菜单中选择了Intellisense ... Update JScript Intellisense ...

不幸的是,这不起作用,更新 Intellisense 时出现以下错误:

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

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

于 2009-02-26T17:31:31.727 回答
0

我遇到了同样的问题,发现有一个适用于 Visual Studio 2008 的修补程序可以解决我的问题:

http://support.microsoft.com/kb/958502

于 2009-04-16T17:07:29.937 回答