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