Miguel A. Castro Architect IDesign SESSION CODE: WEB310
ineta .NET Architect, Developer, & Trainer Microsoft MVP ASP Insider VSX Insider Member of the INETA Speakers Bureau Conference Speaker In IT business since 1986 ineta
What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References
What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References
The Request
Specifies # of result items to return {10} Specifies where to start the search {0} Need to be true if Count and Offset set
The Call
The Response
Type Results Title Description DisplayUrl Url DateTime WebResult Title Url Thumbnail Url Width Height ImageResult Title PlayUrl StaticThumbnail Url Width Height VideoResult Title Url Source Snippet Date NewsResult Value SpellResult Title Url Business PhoneNumber Address StateOrProvince PostalCode Latitude Longitude DisplayUrl PhonebookResult TranslatedTerm TranslationResult
In the Config fileIn Code
What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References
{ "SearchResponse": { "Version":"2.2", "Query": { "SearchTerms":"Miguel A Castro"}, "Web": { "Total": , "Offset":0, "Results": [ { "Title":"Miguel Castro", "Description":"Miguel Castro "Url":" "CacheUrl":" "DisplayUrl":" "DateTime":" T22:38:20Z" }, { "Title":"DotNetDude.com - Miguel A. Castro's Blog", "Description":"Miguel A. Castro's DotNetDude.com... The user...", "Url":" "CacheUrl":" ", "DisplayUrl":"dotnetdude.com", "DateTime":" T13:41:28Z" } ] } Corresponds to Source Types requested in URL
{ "SearchResponse": { "Version":"2.2", "Query": { "SearchTerms":"Miguel A Castro"}, "Web": { "Total": , "Offset":0, "Results": [ { "Title":"Miguel Castro", "Description":"Miguel Castro "Url":" "CacheUrl":" "DisplayUrl":" "DateTime":" T22:38:20Z" }, { "Title":"DotNetDude.com - Miguel A. Castro's Blog", "Description":"Miguel A. Castro's DotNetDude.com... The user...", "Url":" "CacheUrl":" ", "DisplayUrl":"dotnetdude.com", "DateTime":" T13:41:28Z" } ] } Data Contract Object Model BingSearchResultData – top level Response (SearchResponse) Query Web WebResult[] (Results) Title Description Url Data Contracts for REST JSON Mapping
[OperationContract] [WebGet( UriTemplate = "json.aspx?Appid={appId}&Query={query}&Sources=web& Web.Offset=0", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] BingSearchResultData GetWebSearchResults( string appId, string query);
[OperationContract] [WebGet( UriTemplate = "json.aspx?Appid={appId}&Query={query}&Sources=web& Web.Offset=0", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] BingSearchResultData GetWebSearchResults( string appId, string query); Custom method will map to any URL structure you choose. REST-Specific WCF attribute (.NET 3.5+) URL (relative to base) to be called using this method. Arguments in URL MUST match arguments in method. (Note curly braces)
[OperationContract] [WebGet( UriTemplate = "json.aspx?Appid={appId}&Query={query}&Sources=web& Web.Offset=0", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] BingSearchResultData GetWebSearchResults( string appId, string query); REST Service Contract No additional wrapping in metadata Format for data served by this method. Format for data this method will access (our case).
REST Bing Search WebHttpBinding binding = new WebHttpBinding(); binding.Security.Mode = WebHttpSecurityMode.None; WebChannelFactory factory = new WebChannelFactory ( binding, new Uri(" IBingService proxy = factory.CreateChannel(); BingSearchResultData results = proxy.GetWebSearchResults(key, query); BINDING CONTRACT ADDRESS
What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References
FluentSearch Demo var request = FluentSearchLib.FluentSearch.CreateRequest().SearchEngine("bing").SearchFor(txtSearchText.Text).PageSize(5).PageNumber(1).Web.UseKey(“{my app key}").CallbackTo(ResponseCallback, SynchronizationContext.Current); // SearchResponse response = request.Execute(); IAsyncResult asyncResult = request.ExecuteAsync(); private void ResponseCallback(SearchResponse response) { // context.Send(e => DisplayResults((SearchResponse)e), response); DisplayResults(response); } private void DisplayResults(SearchResponse response) { foreach (var item in response.Web.Results) { txtResults.Text += item.Title + Environment.NewLine +...
What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References
Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.
Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.
Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31 st You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year