2009-02-25 26 views
3

我終於得到了智能感知工作的JQuery應用補丁KB958502到Visual Studio 2008和包括此行:如何獲得WCF Ajax服務的智能感知?

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

在我的.js文件的頂部。現在,我試圖找出如何讓智能感知的JavaScript由ScriptManager的的ScriptReference元素生成的客戶端代理(如下圖所示):

<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(... 

,但我沒有得到任何智能感知(例如,如果我輸入的文檔。沒有東西彈出)。對於生成的方法或方法使用的[DataContract]類型,我沒有獲得智能感知。

我相信我是假設爲這些代理和類型獲取Intellisense,但無法弄清楚我可能會做錯什麼。 TIA。

回答

4

是不是 /// <reference path="../Services/DocLookups.svc" /> 不工作?

+0

它最初沒有工作,因爲我在我的崗位說明,但DID的工作,一旦我意識到我必須在MicrosoftAjax.js //參考名稱=「MicrosoftAjax.js」/> .svc「/> 非常感謝您的幫助。 – 2009-02-27 04:03:39

0

感謝斯科特指出,我需要添加

///<reference path... 

線。我不知道它在哪裏被記錄,但我不知道這是WCF生成的客戶端代理所必需的 - 儘管現在給出了相同的習慣用於獲取JQuery的Intellisense的意義。

爲了記錄,我最終不得不使用的線與Scott建議給我的項目結構略有不同。我想:

/// <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 

所以我已經取得了一些進展,但我還沒有應用。