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

时间:2009-02-25 19:02:06

标签: javascript ajax visual-studio-2008 wcf intellisense

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

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

位于我的.js文件的顶部。现在我想弄清楚如何为ScriptManager的ScriptReference元素生成的客户端代理获取JavaScript intellisense(如下所示):

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

客户端代理工作正常 - 即我可以通过它们进行调用,但我没有得到Intellisense。

我的服务是使用.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。

3 个答案:

答案 0 :(得分:4)

没有符合 /// <reference path="../Services/DocLookups.svc" /> 不行吗?

答案 1 :(得分:0)

感谢Scott指出我需要添加

///<reference path... 

线。我不知道它在哪里记录,但我不知道这是WCF生成的客户端代理所必需的 - 虽然现在有意义,因为同样的习惯用于获取JQuery的Intellisense。

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

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

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

不幸的是,这不起作用,我在更新智能感知时遇到以下错误:

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

所以我取得了一些进展,但我还没到那里。

答案 2 :(得分:0)

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

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