MigratingBingSearchAPIApplicationsIntroductionTheBingSearchAPIenablesdevelopersandinformationworkstoembedandcustomizesearchresultsinapplicationsorwebsitesbyusingXMLorJavaScriptObjectNotation(JSON).
Youcanaddsearchfunctionalitytoawebsite,createuniqueconsumerorenterpriseapplications,ordevelopnewmash-ups.
TheBingSearchAPIgivesyouaccesstoweb,image,news,andvideoresults,aswellasrelatedsearchandspellingsuggestions.
TheBingSearchAPI2.
0istransitioningtoanofferingthat'savailableinWindowsAzureMarketplaceviasubscription.
WindowsAzureMarketplaceisacloud-baseddataservicethatenablesdevelopersandinformationworkerstofind,acquire,andconsumepublisheddatasetsandwebservices.
Userssubscribetodatasetsandwebservicesofinterestandcanintegratetheinformationintotheirownapplicationsviastandardizeddataservices.
TheycananalyzethedataonlinebyusingtheServiceExplorertoolorbyusingagrowingbodyoftoolslikePowerPivotinMicrosoftExcel.
ThenewversionoftheBingSearchAPIincludes:Meteredsubscriptionofquerylimits.
HTTPSqueryURLs(sometimescalled"endpoints")thatprovideresultsineitherXMLorJSONmediaformats.
OpenDataProtocol(OData)supportforeasyconsumptionacrossmultipledevelopmentsystems.
Improvedsupportfordatatypes.
TheabilitytomonetizeapplicationsintheWindowsAzureMarketplace.
Accesstofresherresultsandimprovedrelevance.
ThemovetoWindowsAzureMarketplacewillrequireeachcustomertofollowamigrationprocess.
Thisguidedescribesthemigrationprocessandgivesusagesamples.
MigratingtotheBingSearchAPIinWindowsAzureMarketplaceTomigrateyourexistingapplicationfromBingAPI2.
0totheBingSearchAPIinWindowsAzureMarketplace,completethestepsinthissection.
YoucanexpectmigratingtothenewBingSearchAPItoinvolvethefollowingchangesinyourexistingapplication:TargetingofanewqueryURLModeratechangestotherequestandresponseschemasSecurityrequirementtoauthenticateaccesstoyourdatasubscription1.
SubscribetoaBingSearchAPIofferingSelectoneofthefollowingofferings.
ProductofferingCapabilitiesBingSearchAPIProvidesaccesstoBingweb,image,video,news,andrelatedsearchresults,aswellasspellingsuggestionsBingSearchAPI-WebResultsOnlyProvidesaccesstoBingwebresultsonlyAfteryouselectanoffering,chooseanoffervariantthatrepresentsthenumberofqueriesyouwanttosubscribeto.
BingSearchAPIcomesinmanyvariantstomeetyourtrafficdemand,includingafreetime-limitedtrialforprototyping.
SelecttheoffervariantbyclickingtheTRYFREEorBUYbutton.
Afteryouselecttheoffervariant,you'llbeaskedtoprovidebillinginformation,includingacreditcardnumber.
Fortrialoffers,thecreditcardwillbeusedtoconverttheofferintoapaidsubscriptionafterthetrialperiodends.
Ifyoudon'twanttoconverttoapaidoffer,youcancancelyoursubscriptionbeforethetrialperiodends.
WindowsAzureMarketplacewillbillthespecifiedamounttoyourcreditcardeachmonth,foraslongasthesubscriptionisactive.
YoucanviewyouractivesubscriptionsontheMyDatapageinWindowsAzureMarketplace.
2.
ChangeyourqueryURLChangeyourBingSearchAPIqueryURLfromthecurrentlyconfiguredBingSearchAPI2.
0queryURL(thatis,http://api.
bing.
net)tooneofthefollowing,dependingonwhichproductofferingyou'vesubscribedto.
ProductofferingQueryURLBingSearchAPIhttps://api.
datamarket.
azure.
com/Bing/Search/BingSearchAPI-WebResultsOnlyhttps://api.
datamarket.
azure.
com/Bing/SearchWeb/TheServiceExplorertoolinWindowsAzureMarketplacecanhelpyouexperimentwiththenewBingSearchAPIandgeneratequeryURLs.
YoucanaccessServiceExplorerbyusingoneofthefollowinglinks,dependingonwhichproductofferingyou'vesubscribedto.
ProductofferingServiceExplorerlinkBingSearchAPIhttps://datamarket.
azure.
com/dataset/explore/5BA839F1-12CE-4CCE-BF57-A49D98D29A44BingSearchAPI-WebResultsOnlyhttps://datamarket.
azure.
com/dataset/explore/8818F55E-2FE5-4CE3-A617-0B8BA8419F65ThefollowingillustrationisanexampleofdevelopingandrunningaqueryinServiceExplorer.
ThequeryURLisexpressedviatheODataspecification.
ThedifferencesbetweenthisspecificationandBingSearchAPI2.
0areasfollows:BecausestringparameterswillbeusedtogenerateaURL,theymustbeURLencoded.
Soinsteadofbeingenclosedinapostrophes('),thestringparametersaresurroundedbytheASCIIequivalent%27.
Forinstance:https://api.
datamarket.
azure.
com/Bing/Search/WebQuery=%27Xbox%27Note:Ifthequerytextmightcontainnon-alphanumericcharacters,youshouldURLencodetheentirestring.
ThenamesofthecountandoffsetparametershavebeenchangedtocomplywiththeODatastandard.
Furthermore,insteadofhavingadifferentqueryURLforeachresponsetype(JSONversusXML),aspecialODataparameterisused.
ThefollowingtableliststheODataparameters.
ReservedparameterDescriptionEquivalentinBingSearchAPI2.
0DefaultvalueExample$topSpecifiesthenumberofresultstoreturn.
&count=50(50isthemaximum)https://api.
datamarket.
azure.
com/Bing/Search/WebQuery=%27Xbox%27&$top=10$skipSpecifiestheoffsetrequestedforthestartingpointofresultsreturned.
&offset=0https://api.
datamarket.
azure.
com/Bing/Search/WebQuery=%27Xbox%27&$top=10&$skip=20$formatSpecifiestheformatoftheODataresponse.
CurrentoptionsareAtom(forXML)orJSON.
AlternativeformatswereaccomplishedwithdifferentqueryURLs(forexample,xml.
aspxandjson.
aspx)Atomhttps://api.
datamarket.
azure.
com/Bing/Search/WebQuery='Xbox'&$top=10&$skip=20&$format=ATOMFormoreinformationaboutOData,visittheODatawebsite.
Note:TheODatareservedparametersdonotrequirethattheircorrespondingvaluesbeURLencodedandenclosedinapostrophes('),theASCIIequivalent%27.
BingAPIDataMarketsupportsHTTPcompressiontosaveontransferdatavolumeanddelivery.
ToenableHTTPcompression,addheader"Accept-Encoding:gzip"toyourHTTPrequest.
3.
AppendtheserviceoperationtotheendofthequeryURLAserviceoperationisthedatasourcethatistargetedforBingSearchAPIresults.
BingSearchAPI2.
0referencedthisasthe&Source=parameter.
Forinstance,ifthetargeteddatasourceis"web,"appendtheserviceoperationWebtotheendofyourqueryURLasfollows:https://api.
datamarket.
azure.
com/Bing/Search/WebTheserviceoperationsavailableintheBingSearchAPIDataMarketarelistedinthefollowingtable.
ServiceOperationEquivalentinBingSearchAPI2.
0ExampleWebWebhttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10ImageImagehttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10VideoVideohttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10NewsNewshttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10SpellingSuggestionSpellhttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10RelatedSearchRelatedSearchhttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/Web$top=10Compositehttps://api.
datamarket.
azure.
com/Data.
ashx/Bing/Search/CompositeSources=%27web%2bnews%27&Query=%27XBox%27&$top=1Note:Torequestmultipledatasourcesinasinglequery,specifytheserviceoperationnamed"Composite"followedbyitsrequiredparameternamed"Sources".
Thevalueappliedto"Sources"arethenameoftheserviceoperationsconcatenatedwitha+character.
Seethetableaboveforanexampleofasinglequeryrequestingweb&news.
AlsonotethatthenumberofresultsreturnedwiththeODatareservedparameter$toprefertoalldatasourcesspecifiedinthequeryexceptNews.
Newswillalwaysreturnafixednumberof15newsresultswhenusedinaquerywithaCompositeserviceoperation.
4.
SpecifyrequiredandoptionalparametersSpecifytherequiredandoptionalparametersbyappendingparameterizedname/valuepairstothequeryURL,asincommonREST-likeinterfaces.
TheparametersaredocumentedinatableundertheDetailstaboftheofferingthatyou'vesubscribedto.
Forinstance,ifyou'rebuildingaquerywiththerequiredparameterqueryofvalue'XBOX'andtheoptionalparametermarketofvalue'en-GB',appendtheparameterizedname/valuepairstotheendofyourqueryURLasfollows:https://api.
datamarket.
azure.
com/Bing/SearchWeb/WebQuery=%27Xbox%27&Market=%27en-GB%275.
ObtainyouraccountkeyToauthenticateaBingSearchAPIrequestwithWindowsAzureMarketplace,youmustobtainanaccountkey.
ThismodeofauthenticationreplacestheAppIDusedintheBingSearchAPI2.
0.
Youcanobtainyouraccountkeybyusingeitherofthefollowingmethods:GototheAccountKeyspageandaddanewaccountkeyforyourapplication.
Thisistherecommendedmethodbecauseyoucanremovethisaccountkeyifitbecomescompromised.
GototheAccountKeyspageandusethedefaultaccountkey.
6.
InsertthequeryURLintoabrowserToissueyourrequestfortheBingSearchAPI,insertthequeryURLbuiltfromthepreviousstepsintoabrowser.
WindowsAzureMarketplacesupportsBasicAuthenticationtoauthenticaterequeststoyourdatasubscription.
You'llbepromptedforausernameandpasswordfromyourbrowser.
Leavetheuser-namefieldemptyandenteryouraccountkeyinthepasswordfield.
ThebrowserwilldisplayXMLresultsreturnedfromtheBingSearchAPI.
7.
AdjustyourresponseparsinglogicAdjustyourresponseparsinglogictomatchtheupdatedresponseformat.
ThefollowingsectionscomparequeryresponsesbetweenBingSearchAPI2.
0andtheBingSearchAPIthat'savailableinWindowsAzureMarketplace.
ResultscontainerSomechangesweremadetotheelementsthatcontaintheresultsarray.
ThisincludestheSearchResponseelement,theSearchResponse/Queryelement,andtheimmediatechildrenofthesource-type-specificcontainerslikeweb:Webandmms:Image.
Version2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=web&count=2https://api.
datamarket.
azure.
com/Bing/Search/WebQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-Query-SearchTerms-link-web:Web-entry-web:Total-web:Offset-web:Results-contentNote:Otherpropertiesomittedforclarity.
Removeddata:SearchTerms.
Becausethisissentacrossthewireintherequest,itisnotnecessaryintheresponse.
Ifsomeasynchronousprogrammingpatternrequiresthattheresponsebeverified,theidresponsepropertycanbeusedtoobtainthefullrequestURL.
Total.
Iftherearenomorepagesofresults,the/feed/link[@rel='next']propertywillnolongerappear,andthetotalisnolongerneededforenablingpaging.
Offset.
ThisvalueisusedtohelpdevelopersbuildtherequestURLforthenextpageofresults.
IntheODataprotocol,thenextpageofresultsisrequestedviathehrefpropertyof/feed/link[@rel='next'].
ThenextpageofresultscanbeobtainedsimplybyrequestingthisURL.
WebresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=web&count=2https://api.
datamarket.
azure.
com/Bing/Search/WebQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-web:Web-web:Results-web:WebResult-entry-content-m:properties-d:ID-web:Title-d:Title-web:Description-d:Description-web:DisplayURL-d:DisplayUrl-web:URL-d:Url-web:CacheUrl-web:DateTime-web:DeepLinks-web:SearchTagsNote:Otherpropertiesomittedforclarity.
Removeddata:CacheUrl.
Deprecated.
DateTime.
Deprecated.
DeepLinks.
Deprecated.
SearchTags.
Deprecated.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
Renameddata:URL.
ThispropertywasrenamedtoUrl.
DisplayURL.
ThispropertywasrenamedtoDisplayUrl.
ImageresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=image&count=2https://api.
datamarket.
azure.
com/Bing/Search/ImageQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-mms:Image-mms:Results-mms:ImageResult-entry-content-m:properties-d:ID-mms:Title-d:Title-mms:MediaUrl-d:MediaUrl-mms:Url-d:SourceUrl-mms:DisplayUrl-d:DisplayUrl-mms:Width-d:Width-mms:Height-d:Height-mms:FileSize-d:FileSize-mms:ContentType-d:ContentType-mms:Thumbnail-d:Thumbnail-mms:Url-d:MediaUrl-mms:ContentType-d:ContentType-mms:Width-d:Width-mms:Height-d:Height-mms:FileSize-d:FileSizeNote:Otherpropertiesomittedforclarity.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
Renameddata:URL.
ThispropertywasrenamedtoSourceUrl.
VideoresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=image&count=2https://api.
datamarket.
azure.
com/Bing/Search/ImageQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-mms:Image-mms:Results-mms:VideoResult-entry-content-m:properties-d:ID-mms:Title-d:Title-mms:PlayUrl-d:MediaUrl-mms:SourceTitle-mms:RunTime-d:RunTime-mms:ClickThroughPageUrl-d:DisplayUrl-mms:StaticThumbnail-d:Thumbnail-mms:Url-d:MediaUrl-mms:ContentType-d:ContentType-mms:Width-d:Width-mms:Height-d:Height-mms:FileSize-d:FileSizeNote:Otherpropertiesomittedforclarity.
Removeddata:SourceTitle.
Deprecated.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
Renameddata:PlayUrl.
ThispropertywasrenamedtoMediaUrl.
ClickThroughPageUrl.
ThispropertywasrenamedtoDisplayUrl.
StaticThumbnail.
ThispropertywasrenamedtoThumbnail.
StaticThumbnail/Url.
ThispropertywasrenamedtoMediaUrl.
NewsresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=news&count=2https://api.
datamarket.
azure.
com/Bing/Search/NewsQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-news:News-news:Results-news:NewsResult-entry-content-m:properties-d:ID-news:Title-d:Title-news:Url-d:Url-news:Source-d:Source-news:Snippet-d:Description-news:Date-d:Date-news:BreakingNewsNote:Otherpropertiesomittedforclarity.
Removeddata:BreakingNews.
Deprecated.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
Renameddata:Snippet.
ThispropertywasrenamedtoDescription.
RelatedsearchresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=RelatedSearch&count=2https://api.
datamarket.
azure.
com/Bing/Search/RelatedSearchQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-rs:RelatedSearch-rs:Results-rs:RelatedSearchResult-entry-content-m:properties-d:ID-rs:Title-d:Title-rs:Url-d:BingUrlNote:Otherpropertiesomittedforclarity.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
SpellingsuggestionresultsVersion2.
0WindowsAzureMarketplaceRequestshttp://api.
search.
live.
net/xml.
aspxAppid=App&query=odata&sources=spell&count=2https://api.
datamarket.
azure.
com/Bing/Search/SpellingSuggestionsQuery=%27odata%27&$top=2ResponseTreesSearchResponseFeed-spl:Spell-spl:Results-spl:SpellResult-entry-content-m:properties-d:ID-spl:Value-d:ValueNote:Otherpropertiesomittedforclarity.
Addeddata:ID.
Aresultset/uniqueIDforthisrow.
UsagesamplesThissectionshowsusagesamplesinavarietyoflanguagestohelpdevelopersstartusingthenewBingSearchAPI.
UsingtheAPIwiththeMicrosoft.
NETFrameworkviaC#ThemoststraightforwardapproachtousingtheAPIwithC#istodownloadaserviceproxyfromtheBingAPIlandingpageinWindowsAzureMarketplace.
Afteryousubscribetotheoffer,you'llseeabuttonlikethisonedirectlybelowtheoffervariantslist:Ifyouclickthisbutton,youcandownloadtheproxytoyourcomputer.
Next,youcanmovethislibraryintoyourprojectdirectoryandaddittoyourproject.
Togetstartedwiththeproxy,seethefirsttwosectionsofWalkthrough:MicrosoftTranslatorinaC#ConsoleApplication.
Aftertheproxyhasbeenaddedtoyourproject,youcanstartcodingagainstitalmostimmediately.
Thefollowingsampleconsoleapplicationsynchronouslyperformsanimagesearchanddownloadsthesearchresults.
Important:BesuretoaddareferencetoSystem.
Data.
Services.
Clientbeforeyoubuildyourproject.
usingSystem;usingSystem.
Net;namespaceImageSearchConsole{classProgram{staticvoidMain(string[]args)varbingContainer=newBing.
BingSearchContainer(newUri("https://api.
datamarket.
azure.
com/Bing/Search/"));replacethisvaluewithyouraccountkeyvaraccountKey="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";thenextlineconfiguresthebingContainertouseyourcredentials.
bingContainer.
Credentials=newNetworkCredential(accountKey,accountKey);nowwecanbuildthequeryvarimageQuery=bingContainer.
Image("xbox",null,null,null,null,null);varimageResults=imageQuery.
Execute();foreach(varresultinimageResults)Console.
WriteLine(result.
Title);Console.
ReadLine();}}UsingtheAPIwiththeMicrosoft.
NETFrameworkviaVisualBasicBecauseofthepopularityofworkingwithXMLcontentinVisualBasic,thefollowingsamplehasbeentailoredtoconsumetherawAtomresponsefromtheBingSearchAPIdirectlyinVisualBasic.
NET.
ThesampleaimstoexecuteasimpleimagequeryagainsttheBingSearchAPIandtoprintsomeattributeofeachimageresponsetotheconsole.
Tousethissample,createanewVisualBasicconsoleapplicationandpastethesamplecodeintothemain.
vbfile.
ImportsSystem.
XmlImportsSystem.
NetModuleModule1SubMain()ReplacethisvaluewithyouraccountkeyDimaccountKeyAsString="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="TheWindowsAzureMarketplaceServiceRootUrlfortheBingSearchofferDimserviceRootAsString="https://api.
datamarket.
azure.
com/Bing/Search/"TheQuerytypewe'reperformingDimimageQueryRootAsString=serviceRoot+"Image"TheQuerystring,surroundedbyUrlEncodedquotesDimimageQueryAsString=imageQueryRoot+"Query=%27xbox%27"AnXmlDocumentwewillusetoreadtheresultsDimdocumentAsXmlDocument=NewXmlDocument()ThenextfourlinesconfiguretheXmlDocumenttouseyourcredentialswhenqueryingtheImageSearchAPIDimaccountCredentialAsNewNetworkCredential(accountKey,accountKey)DimresolverAsNewXmlUrlResolver()resolver.
Credentials=accountCredentialdocument.
XmlResolver=resolverWithcredentialsconfiguredwedownloadthequeryresultsdocument.
Load(imageQuery)ThisnamespacemanagerwillassistwithparsingtheresultsDimnamespaceManagerAsXmlNamespaceManager=NewXmlNamespaceManager(document.
NameTable)namespaceManager.
AddNamespace("atom","http://www.
w3.
org/2005/Atom")namespaceManager.
AddNamespace("m","http://schemas.
microsoft.
com/ado/2007/08/dataservices/metadata")namespaceManager.
AddNamespace("d","http://schemas.
microsoft.
com/ado/2007/08/dataservices")Thisquerygetsthe"Next"linkfortheresultset.
document.
Loadthisvaluetogetthenextsetofresults.
IfthevalueisNothingthentherearenomoreresults.
DimnextResultSetAsString=document.
SelectSingleNode("/atom:feed/atom:link[@rel='next']/@href",namespaceManager).
ValueThisgetsthepropertiesnodeforeachImagesearchresultDimimageResultsAsXmlNodeList=document.
SelectNodes("/atom:feed/atom:entry/atom:content/m:properties",namespaceManager)ForEachimageResultAsXmlNodeInimageResultsSelecttheTitleelementfromthisimageResultDimtitleAsString=imageResult.
SelectSingleNode(".
//d:Title",namespaceManager).
InnerTextConsole.
WriteLine(title)NextEndSubEndModuleUsingtheAPIwithSilverlightSilverlightisaMicrosoftframeworkthatenablesdeveloperstobuildRichInternetApplications(RIAs)byusingmanyofthesame.
NETFrameworklibrariesandprogramminglanguagesthatthey'reaccustomedtousinginclassic.
NETapplications.
Becauseofitsstrongintegrationwithbrowsersaswellaswithimagesandothermedia,it'sausefulclientforbuildingapplicationsviatheBingSearchAPI.
LikeJSONapplicationsthatresideinthebrowser,Silverlightapplicationscan'ttypicallyinvokeservices(rawHTTPorSOAP)ondomainsotherthanthedomainfromwhichtheSilverlightapplicationisdownloaded.
ButbecauseWindowsAzureMarketplacepublishesacross-domainpolicyfileattherootofitsdomain(https://api.
datamarket.
azure.
com/crossdomain.
xml)thatallowsRIAplatformslikeSilverlighttoaccessitsqueryURLs,it'spossibletousetheAPIfromSilverlight.
BecauseSilverlightisreallya.
NETprogrammingenvironment,thechoicesforAPIinvocationarethesameastheearlier.
NETsamples(althoughSilverlightalsohasaJSON-parsingobjectmodel).
Youcanusethesameproxyclassthatyousawintheearlier.
NETsamples.
Tohelpdevelopersbuildveryresponsiveapplications,however,SilverlightrequiresthatWebrequestsareperformedasynchronouslyratherthansynchronously.
ThefollowingsampleshowsaSilverlightapplicationobtainingdatafromtheBingImageSearchservice.
ItassumesthatyouhavealreadyaddedtheBingproxytoyourapplication,aswasshownintheC#sample.
usingSystem;usingSystem.
Data.
Services.
Client;usingSystem.
Linq;usingSystem.
Net;usingSystem.
Windows;usingSystem.
Windows.
Controls;namespaceBingApp{publicpartialclassMainPage:UserControl{publicMainPage()InitializeComponent();privatevoidbutton1_Click(objectsender,RoutedEventArgse)varbingContainer=newBing.
BingSearchContainer(newUri("https://api.
datamarket.
azure.
com/Bing/Search/"));replacethisvaluewithyouraccountkeyvaraccountKey="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";thenexttwolinesconfigurethebingContainertouseyourcredentials.
bingContainer.
Credentials=newNetworkCredential(accountKey,accountKey);note,thislinewasnotrequiredfortheC#consoleappbingContainer.
UseDefaultCredentials=false;thenexttwolinesdefinetherequestfordataandvarimageQuery=bingContainer.
Image("xbox",null,null,null,null,null);imageQuery.
BeginExecute(newAsyncCallback(this.
ImageResultLoadedCallback),imageQuery);privatevoidImageResultLoadedCallback(IAsyncResultar)varimageQuery=(DataServiceQuery)ar.
AsyncState;varenumerableImages=imageQuery.
EndExecute(ar);varimagesList=enumerableImages.
ToList();hereyoucouldalsochoosetosimplybindtheresultslisttoacontrolinyourUI.
Instead,wewillsimplyiterateovertheresults.
foreach(varimageinimagesList)dosomethingwiththeimage,orbindtheimage}}UsingtheAPIwithPHPPHPhasapowerfulJSONparsingmechanism.
BecausePHPisadynamiclanguage,theparsingmechanismenablesPHPdeveloperstoprogramagainstaJSONobjectgraphinastraightforwardway.
ThefollowingsampleshowsaPHPpagethatsendsarequesttotheJSONinterfacebyusingthefile_get_contentsfunctiontocalltheJSONqueryURL,andthejson_decodefunctiontoturntheresultsintoanobjectgraphthatcanbewalkedandturnedintoHTML.
PHPBing">Typeinasearch:"/>array('request_fulluri'=>true,'header'=>"Authorization:Basic".
base64_encode($accountKeyaccountKey))));$request=$WebSearchURL.
urlencode(POST["searchText"echo($request);$response=file_get_contents($request,0,$context);$jsonobj=json_decode($response);echo('');foreach($jsonobj->d->resultsas$value){echo('MediaURL.
'">');echo('Thumbnail->MediaUrl.
'">');}echo("");}>UsingtheAPIwithotherdevelopmentenvironmentsWindowsAzureMarketplaceexposestheBingSearchAPIbyusingthewell-knownandbroadlysupportedODataprotocol.
Inadditiontoprovidingacommonlanguagewithwhichtoexposedata,ODataprovidesBingSearchAPIcustomerswithabroadsetoftoolsandlibrariesthattheycanusetoconsumeODataservicesliketheBingSearchAPIinavarietyofprogramminglanguages.
TolearnmoreaboutthelibrarysupportavailableforOData,seetheODataSDK.
Ofcourse,youcanalsousetheBingSearchAPItofindwebresultsforthequery"odatasdk".
TobrowsetheBingSearchAPIODataservices,youcanquerytheODatametadata,whichreturnsacompletedescriptionofhowtheservicecanbecalled,whatparametersitexpects,andwhatdatastructuresitreturns.
Itthusservesaroughlysimilarpurposeasamethodsignatureinaprogramminglanguage.
ToaccesstheODatametadata,appendtheODatakeyword$metadatatotheendofthequeryURLofthedatasubscriptionoftheBingSearchAPIofferingthatyouselected,asshowninthefollowingtable.
ProductofferingQueryURLBingSearchAPIhttps://api.
datamarket.
azure.
com/Bing/Search/$metadataBingSearchAPI-WebResultsOnlyhttps://api.
datamarket.
azure.
com/Bing/SearchWeb/$metadata
已经有一段时间没有分享阿里云服务商的促销活动,主要原因在于他们以前的促销都仅限新用户,而且我们大部分人都已经有过账户基本上促销活动和我们无缘。即便老用户可选新产品购买,也是比较配置较高的,所以就懒得分享。这不看到有阿里云金秋活动,有不错的促销活动可以允许产品新购。即便我们是老用户,但是比如你没有购买过他们轻量服务器,也是可以享受优惠活动的。这次轻量服务器在金秋活动中力度折扣比较大,2G5M配置年付...
95idc是一家香港公司,主要产品香港GIA线路沙田CN2线路独服,美国CERA高防服务器,日本CN2直连服务器,即日起,购买香港/日本云主机,在今年3月份,95IDC推出来一款香港物理机/香港多ip站群服务器,BGP+CN2线路终身7折,月付350元起。不过今天,推荐一个价格更美的香港物理机,5个ip,BGP+CN2线路,月付299元起,有需要的,可以关注一下。95idc优惠码:优惠码:596J...
修罗云怎么样?修罗云是一家国内老牌商家,修罗云商家以销售NAT机器起家,国内的中转机相当不错,给的带宽都非常高,此前推荐的也都是国内NAT VPS机器。今天,云服务器网(www.yuntue.com)小编主要介绍一下修罗云的香港云服务器,适合建站,香港沙田cn2云服务器,2核2G,5M带宽仅70元/月起,同时香港香港大带宽NAT VPS低至50元/月起,性价比不错,可以尝试一下!点击进入:修罗云官...
file_get_contents为你推荐
技术参数及要求:支持ipad支持ipad重庆网通重庆联通现在有哪些资费???win7关闭445端口如何快速关闭445端口谷歌sbSb是什么意思?bitchinaBTchina和VeryCD是什么意思?这与87.53有什么关系?ios11.0.2苹果6s升级ios11.0.2用着怎么样 掉电快吗ios11.0.2ios11.0.2怎么降级ios10.3.3易氧源易氧源制氧机和鱼跃制氧机哪个牌子的好??
双线vps 个人域名备案 主机屋 highfrequency 512m 网站监控 服务器cpu性能排行 线路工具 骨干网络 qingyun php空间推荐 183是联通还是移动 上海服务器 路由跟踪 主机管理系统 贵阳电信 lamp怎么读 工信部icp备案查询 群英网络 登陆qq空间 更多