Presentation is loading. Please wait.

Presentation is loading. Please wait.

Miguel A. Castro Architect IDesign SESSION CODE: WEB310.

Similar presentations


Presentation on theme: "Miguel A. Castro Architect IDesign SESSION CODE: WEB310."— Presentation transcript:

1 Miguel A. Castro Architect IDesign miguel.castro@idesign.net SESSION CODE: WEB310

2 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 miguel.castro@idesign.net

3

4

5

6 What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References

7

8

9

10 What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References

11

12 The Request

13

14 Specifies # of result items to return {10} Specifies where to start the search {0} Need to be true if Count and Offset set

15 The Call

16 The Response

17

18 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

19

20 In the Config fileIn Code

21 What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References

22

23

24 { "SearchResponse": { "Version":"2.2", "Query": { "SearchTerms":"Miguel A Castro"}, "Web": { "Total":8550000, "Offset":0, "Results": [ { "Title":"Miguel Castro", "Description":"Miguel Castro castro@lcs.mit.edu", "Url":"http:\/\/www.pmg.lcs.mit.edu\/~castro\/", "CacheUrl":"http:\/\/cc.bingj.com\/cache.aspx?q=migu..", "DisplayUrl":"www.pmg.lcs.mit.edu\/~castro", "DateTime":"2010-05-01T22:38:20Z" }, { "Title":"DotNetDude.com - Miguel A. Castro's Blog", "Description":"Miguel A. Castro's DotNetDude.com... The user...", "Url":"http:\/\/dotnetdude.com\/", "CacheUrl":"http:\/\/cc.bingj.com\/cache.aspx?q=miguel+a+ca.. ", "DisplayUrl":"dotnetdude.com", "DateTime":"2010-05-01T13:41:28Z" } ] } Corresponds to Source Types requested in URL

25

26 { "SearchResponse": { "Version":"2.2", "Query": { "SearchTerms":"Miguel A Castro"}, "Web": { "Total":8550000, "Offset":0, "Results": [ { "Title":"Miguel Castro", "Description":"Miguel Castro castro@lcs.mit.edu", "Url":"http:\/\/www.pmg.lcs.mit.edu\/~castro\/", "CacheUrl":"http:\/\/cc.bingj.com\/cache.aspx?q=migu..", "DisplayUrl":"www.pmg.lcs.mit.edu\/~castro", "DateTime":"2010-05-01T22:38:20Z" }, { "Title":"DotNetDude.com - Miguel A. Castro's Blog", "Description":"Miguel A. Castro's DotNetDude.com... The user...", "Url":"http:\/\/dotnetdude.com\/", "CacheUrl":"http:\/\/cc.bingj.com\/cache.aspx?q=miguel+a+ca.. ", "DisplayUrl":"dotnetdude.com", "DateTime":"2010-05-01T13:41:28Z" } ] } Data Contract Object Model BingSearchResultData – top level Response (SearchResponse) Query Web WebResult[] (Results) Title Description Url Data Contracts for REST JSON Mapping

27

28 [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);

29 [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)

30 [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).

31

32 REST Bing Search WebHttpBinding binding = new WebHttpBinding(); binding.Security.Mode = WebHttpSecurityMode.None; WebChannelFactory factory = new WebChannelFactory ( binding, new Uri("http://api.bing.net")); IBingService proxy = factory.CreateChannel(); BingSearchResultData results = proxy.GetWebSearchResults(key, query); BINDING CONTRACT ADDRESS

33

34

35 What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References

36

37 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 +...

38 What is Bing The API and its Services Using the SOAP API Using the REST API The FluentSearch Toolkit Summary References

39

40

41 Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

42 Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

43 www.microsoft.com/teched www.microsoft.com/learning http://microsoft.com/technet http://microsoft.com/msdn

44

45 Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31 st http://northamerica.msteched.com/registration You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year

46

47


Download ppt "Miguel A. Castro Architect IDesign SESSION CODE: WEB310."

Similar presentations


Ads by Google