Answered by:
Need helping calling Live Search API from VS 2008

Question
-
Hi,
(This may just be a beginner's problem or maybe it's something to do with VS 2008.)
I want to call the Live Search 2.0 API in a VS 2008 C# project. (My original project is Silverlight, but I'm having the same problem with WinForms). So, I signed up for an API key and then in my project I added a "Service References" to the web service.
That lets me see all kinds of interesting new types (e.g. Query, WebResponse) and it defines "SearchResponse1", but I don't see how I actually create (or access) the service.
In the SDK example, LiveSearchService seems to be defined in it's auto-generated Reference.cs. Then it does:
LiveSearchService
I don't see LiveSearchService in my Reference.cs. I notice that the SDK is VS 2007, not 2008. Does that mater?
Thanks!
- Carl
Thursday, November 27, 2008 11:14 PM
Answers
-
For some reason the publishing system removed a piece of my code sample.
The using and import statement should be prefixed by your application's namespace, as in
Code Snippetusing [YourNamespace].LiveSearchServiceReference;or
Code SnippetImports [YourNamespace].LiveSearchServiceReference
Monday, December 1, 2008 3:26 AM
All replies
-
I'm also working with Visual Studio 2008.
I just recreated a simple new website and added the web reference to http://api.search.live.net/search.wsdl?AppID=YourAppId and then proceeded to put a using net.live.search.api; statement with my other using statements in the codebehind file and I had access to the LiveSearchService class with intellisense.
Did I make a mistake by adding a web reference instead of a service reference?
I'm a newbie, thanks.Saturday, November 29, 2008 12:59 AM -
aj_newbie got it right. Just use a web reference instead of a service reference.
HTH
--Alessandro
Sunday, November 30, 2008 1:45 AM -
In my web project, I see a "Add Web Service", but in the Silverlight project it doesn't seem to be offered. I found this MSDN article: "Breaking Changes in Silverlight 2". It says:
In Visual Studio, Use "Add Service Reference" Instead of "Add Web Reference"Sunday, November 30, 2008 11:57 PM -
There are two solutions, both simple.
Solution 1: use an interface more malleable than SOAP (for example JSON) and serialize the response in an object using the JSON Serializer (code left for when my son does not want to play
).
Solution 2: realize that a WCF service is is a superset of a SOAP webservice, and find out that binding to a service through its WSDL is exactly the same as binding to a web service with one more operation to do.
A quick cheatsheet of how to do it:
1) add a service reference to http://api.search.live.net/search.wsdl?appid=your appid
2) select LiveSearchService (NOT the port type)
3) name it LiveSearchServiceReference
4) in your code file add
Code Snippetusing .LiveSearchServiceReference; //C#or
Code SnippetImports .LiveSearchServiceReference 'VB.net
5) where you need to instantiate your service do (C#)
Code SnippetLiveSearchPortTypeClient client = new LiveSearchPortTypeClient();
client.Open();
SearchResponse searchResponse;
searchResponse = client.Search(searchRequest);
or (VB.net)
Code Snippetclient.Open()
Dim searchResponse As SearchResponsesearchResponse = client.Search(searchRequest)
From here on everything is exactly how it was before.
HTH
--Alessandro
Monday, December 1, 2008 3:19 AM -
For some reason the publishing system removed a piece of my code sample.
The using and import statement should be prefixed by your application's namespace, as in
Code Snippetusing [YourNamespace].LiveSearchServiceReference;or
Code SnippetImports [YourNamespace].LiveSearchServiceReference
Monday, December 1, 2008 3:26 AM -
Thanks! That worked great with one limitation. (Silverlight doesn't seem to support "Open" or "Search". But "OpenAsync" and "SearchAysnc" work fine).
The key is
LiveSearchPortTypeClient client = new LiveSearchPortTypeClient();
I don't see any documentation on this so thanks much for giving the answer.
- Carl
Monday, December 1, 2008 5:32 AM -
Hm, this doesn't work fine for me to:
searchResponse = client.SearchAsync(sr); Cannot implicitly convert type 'void' to 'WebServices.LiveSearch.SearchResponse'
Any ideas?Monday, April 6, 2009 12:44 PM -
am having the same prb, using Silverlight
Following is my code
LiveSearchPortTypeClient client = new LiveSearchPortTypeClient();
client.OpenAsync();
SearchRequest request = BuildRequest();
SearchResponse searchResponse;
//searchResponse = client.Search(request);
searchResponse = client.SearchAsync(request);
I get the above mentioned error "Error 3 Cannot implicitly convert type 'void' to 'SI.LiveSearchServiceRef.SearchResponse'
how do I get rid of this....
ClatonhTuesday, April 21, 2009 6:54 PM -
I didn't find out what to do with this error, but at least my code is working now. Maybe this helps you:
LiveSearchPortTypeClient client = new LiveSearchPortTypeClient(); client.OpenAsync();
client.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(proxy_SearchCompleted); client.SearchAsync(request); (...) void proxy_SearchCompleted(object sender, SearchCompletedEventArgs e) { displayItem.ItemsSource = e.Result.(...) }Friday, April 24, 2009 6:37 AM