Service undefined error using Ajax while attepting to access Bing 2.0 API

Aug 26 2009 3:01 PM
When I attempt to call Bing 2.0 API from clientside javascript I get this error: Microsoft JScript runtime error: 'BingSearchWithAjax' is undefined Can anyone help clue me in to what I'm doing wrong? The steps I took are as follows: Open Visual Studio 2008 Click File->New->Website choose Web site with ASP.NET 2.0 Web Site template rename default.aspx to BingAjaxClient.aspx ensure code behind file class name matches new Inherits:BingAjaxClient Add reference to Bing 2.0 API as described here: http://msdn.microsoft.com/en-us/library/dd250965.aspx Add new WCF Ajax service: Right click project name and choose Add New Item from the context menu that appears select Ajax-enabled WCF Service give it the name BingSearchWithAjax.svc and click Add it will add a code behind file to the App_Code folder named BingSearchWithAjax.cs add the following code to the BingSearchWithAjax.cs file: using System; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; // import Bing API using Bing.API; //normally net.bing.api; using System.Collections.Generic; [ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class BingSearchWithAjax { [OperationContract] public List Search(string query) { BingService srchClient = new BingService(); SearchRequest req = new SearchRequest(); req.AppId = "D4CE339EAFDAA4903E7499C24ADDF81E55DD6BDB"; req.Query = query; req.Market = "en-us"; req.Sources = new SourceType[] { SourceType.Web }; req.Adult = AdultOption.Moderate; req.Web = new WebRequest(); req.Web.Options = new WebSearchOption[] { WebSearchOption.DisableHostCollapsing, WebSearchOption.DisableQueryAlterations }; SearchResponse srchResponse = srchClient.Search(req); // create links based on the search results List li = new List(); Console.WriteLine("result"); foreach (WebResult res in srchResponse.Web.Results) { LinkInfo link = new LinkInfo(); link.url = res.Url; link.title = res.Title; li.Add(link); } return li; } [DataContract] public class LinkInfo { [DataMember] public string url { get; set; } [DataMember] public string title { get; set; } } } add the following code to the BingAjaxClient.aspx form: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BingAjaxClient.aspx.cs" Inherits="BingAjaxClient" %> Ajax-Enabled Bing Search

Ajax-Enabled Bing Search Client

Thanks, Brandon Prescott