Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm really sorry to bother you guys but I've been trying for two days now. I am currently trying to follow your example at http://www.codeproject.com/KB/cs/BingSearch.aspx and I am cannot go past this error


using (LiveSearchService service = new LiveSearchService())
{

The type or namespace name 'LiveSearchService' could not be found (are you missing a using directive or an assembly reference?)


now create an object of |LiveSearchPortTypeClient| which is the basic Endpoint class.

Assume this is where I went wrong,because I do know to how to create an Endpoint class:




- Brian






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using WindowsFormsApplication2.BingService;


namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // Replace the following string with the AppId you received from the
        // Bing Developer Center.
        const string BingMapsKey = "xxxxxx";


        private void btnTranslate_Click(object sender, EventArgs e)
        {
            string strTranslatedText = null;
            try
            {
                TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();
                client = new TranslatorService.LanguageServiceClient();
                strTranslatedText = client.Translate("xxxxxx", txtTraslateFrom.Text, "es", "en");
                txtTranslatedText.Text = strTranslatedText;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
        }
        public string SearchOutput(string AppId, string query, int offset, int no_of_res)
        {
            using (LiveSearchService service = new LiveSearchService())
            {
                try
                {
                    SearchRequest request = new SearchRequest();
                    request.AppId = AppId;
                    request.Query = query;
                    request.Sources = new SourceType[] { SourceType.Web }; //You may specify multiple
                    request.Version = "2.0";
                    request.Market = "en-us";
                    request.Adult = AdultOption.Moderate;
                    request.AdultSpecified = true;
                   // request.Web = new WebRequest();
                    //request.Web.Count = no_of_res;
                    //request.Web.CountSpecified = true;
                    //request.Web.Offset = offset;
                    //SearchResponse response = service.Search(request);
                   // return GetResponsestring(response);
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }
        }



    }

    }
Posted

 
Share this answer
 
Following the Google Example does not work..
 
Share this answer
 
If you think that you went wrong with LiveSearchPortTypeClient, then as per the article, while Adding a service reference you have to choose LiveSearchPortTypeClient from LiveSearchSerice node.
 
Share this answer
 
I think I got it now. Thank you for the help

<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Xml;<br />
<br />
//using WindowsFormsApplication2.BingService;<br />
using WindowsFormsApplication2.LiveSearchService;<br />
<br />
//using WindowsFormsApplication2.net;<br />
//using WindowsFormsApplication2.Search;<br />
//using WindowsFormsApplication2.BingSearch;<br />
<br />
<br />
<br />
<br />
<br />
namespace WindowsFormsApplication2<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        // Replace the following string with the AppId you received from the<br />
        // Bing Developer Center.<br />
        const string AppId = "xxxx";<br />
<br />
<br />
<br />
<br />
        private void btnTranslate_Click(object sender, EventArgs e)<br />
        {<br />
            string strTranslatedText = null;<br />
            try<br />
            {<br />
                TranslatorService.LanguageServiceClient client = new TranslatorService.LanguageServiceClient();<br />
                client = new TranslatorService.LanguageServiceClient();<br />
                strTranslatedText = client.Translate("xxxx", txtTraslateFrom.Text, "es", "en");<br />
                txtTranslatedText.Text = strTranslatedText;<br />
               <br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show(ex.Message);<br />
            }<br />
        }<br />
<br />
        private void results9DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
        {<br />
            // When the content in a cell is clicked check to see if it is the Url column.<br />
            // If it is, pass the url to the Process.Start method to open the web page.<br />
           // if (results9DataGridView.Columns[e.ColumnIndex].DataPropertyName == "Url")<br />
           // {<br />
           //     System.Diagnostics.Process.Start(results9DataGridView.SelectedCells[0].Value.ToString());<br />
           // }<br />
<br />
        }<br />
<br />
<br />
        private uint RunSearchRequest(string query, uint offset, uint count)<br />
        {<br />
            // Create an instance of the service.<br />
            BingPortTypeClient searchService =  new BingPortTypeClient();<br />
<br />
            // Instantiate a new search request.<br />
            SearchRequest request = new SearchRequest();<br />
            //LiveSearchService.SearchResponse response = new LiveSearchService.WebResponse();<br />
            SearchResponse searchResponse =new SearchResponse();<br />
            // common response Fields<br />
           // <br />
<br />
            // Common request fields (required)<br />
            request.AppId = AppId;<br />
            request.Query = query;<br />
            request.Sources = new SourceType[] { SourceType.Phonebook };<br />
<br />
            // Common request fields (optional)<br />
            request.Version = "2.0";<br />
            request.Market = "en-us";<br />
            request.Adult = AdultOption.Moderate;<br />
            request.AdultSpecified = true;<br />
            request.Options = new SearchOption[]<br />
        {<br />
            SearchOption.EnableHighlighting<br />
        };<br />
           <br />
            // PhoneBook-specific request fields (optional)<br />
            request.Phonebook = new PhonebookRequest();<br />
            request.Phonebook.Count = count;<br />
            request.Phonebook.CountSpecified = true;<br />
            request.Phonebook.Offset = offset;<br />
            request.Phonebook.OffsetSpecified = true;<br />
            request.Phonebook.SortBy = PhonebookSortOption.Default;<br />
<br />
<br />
<br />
<br />
       <br />
<br />
            //this.resultsBindingSource.DataSource = request;<br />
<br />
           searchResponse = searchService.Search(request);<br />
           searchResponse.Phonebook.TotalSpecified = true;<br />
<br />
            string results = "";<br />
<br />
            if (searchResponse.Phonebook.Results.Length > 0)<br />
            {<br />
                StringBuilder resultList = new StringBuilder("");<br />
                for (int i = 0; i < searchResponse.Phonebook.Results.Length; i++)<br />
                {<br />
<br />
                    resultList.Append(String.Format("{0}.   {1} {2} {3} {4} {5} \n",<br />
                        offset+i,<br />
                        searchResponse.Phonebook.Results[i].Title,<br />
                        searchResponse.Phonebook.Results[i].PhoneNumber,<br />
                        searchResponse.Phonebook.Results[i].Latitude.ToString(),<br />
                        searchResponse.Phonebook.Results[i].Longitude.ToString(),<br />
                        searchResponse.Phonebook.Results.Length.ToString()<br />
<br />
<br />
                        ));<br />
                }<br />
<br />
                results = resultList.ToString();<br />
                tn.Text += results;<br />
                //resultsBindingSource = results;<br />
            }<br />
            else<br />
            {<br />
                return 0;<br />
                // tn.results = "No results found";<br />
            }<br />
<br />
            return (uint)searchResponse.Phonebook.Results.Length;<br />
            //return searchResponse.Phonebook.Total;<br />
        }<br />
<br />
   <br />
        void Do_Search(string query)<br />
        {<br />
            uint count = 25;<br />
            uint offset = 0;<br />
            uint totalLeft;<br />
            uint x = 0; ;<br />
            totalLeft = RunSearchRequest(query, offset, count);<br />
            while (totalLeft == count)<br />
            {<br />
                x++;<br />
                if (totalLeft < count)<br />
                {<br />
                    RunSearchRequest(query, offset, totalLeft);<br />
                    totalLeft = 0;<br />
                }<br />
                else<br />
                {<br />
                    offset = (count * x);<br />
                    totalLeft = RunSearchRequest(query, offset, count);<br />
                }<br />
<br />
<br />
                t2.Text += offset + " " + totalLeft + "\n";<br />
                //System.Threading.Thread.Sleep(500);<br />
<br />
            };<br />
<br />
        }<br />
        private void searchButton_Click(object sender, EventArgs e)<br />
        {<br />
            Do_Search(searchCriteriaTextBox.Text);<br />
        }<br />
      }<br />
    }<br />
     <br />
 <br />
<br />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900