3

I have to make an application which is able to use Bing Search API ( SOAP Services) with java.It must do a specific search for a word.Here is my code :

    import com.google.code.bing.search.client.BingSearchClient;
    import com.google.code.bing.search.client.BingSearchServiceClientFactory;
    import com.google.code.bing.search.client.BingSearchClient.SearchRequestBuilder;
    import com.google.code.bing.search.schema.AdultOption;
    import com.google.code.bing.search.schema.SearchOption;
    import com.google.code.bing.search.schema.SearchRequest;
    import com.google.code.bing.search.schema.SearchResponse;
    import com.google.code.bing.search.schema.SourceType;
    import com.google.code.bing.search.schema.web.WebResult;
    import com.google.code.bing.search.schema.web.WebSearchOption;
public class MyApp {    
   String apikey = "****************";
   String searchword="google";
     public static void main(String[] args){
BingSearchServiceClientFactory factory = BingSearchServiceClientFactory.newInstance();
    BingSearchClient client = factory.createBingSearchClient();
    SearchRequestBuilder builder = client.newSearchRequestBuilder();
    builder.withAppId(apikey);
    builder.withQuery(searchword);
    builder.withSourceType(SourceType.WEB);
    builder.withVersion("2.0");
    builder.withMarket("en-us");
    builder.withAdultOption(AdultOption.MODERATE);
    builder.withSearchOption(SearchOption.ENABLE_HIGHLIGHTING);
    builder.withWebRequestCount(10L);
    builder.withWebRequestOffset(0L);
    builder.withWebRequestSearchOption(WebSearchOption.DISABLE_HOST_COLLAPSING);        
    builder.withWebRequestSearchOption(WebSearchOption.DISABLE_QUERY_ALTERATIONS);
    SearchResponse response = client.search(builder.getResult());

    for (WebResult result : response.getWeb().getResults()) {
            System.out.println(result.getTitle());
            System.out.println(result.getDescription());
            System.out.println(result.getUrl());
            System.out.println(result.getDateTime());
    }
}
    }

I found this http://code.google.com/p/bing-search-java-sdk/ site. I get my appkey from Azure MarketPlace. I get an error : java.lang.NullPointerException at the line for loop that will show response. That means response is null. I don't understand what I am missing .

medusalith
  • 151
  • 1
  • 3
  • `String searchword="google";` You're searching for Google on Bing? Maybe MS has trouble finding the competition. ;) – Andrew Thompson Jun 03 '12 at 12:09
  • No, the word "google" just for example.I tried to define a word by the variable `searcword` . I must make an application java using bing Soap serach services with this site : [api.search.live.net/search.wsdl](http://api.search.live.net/search.wsdl) – medusalith Jun 03 '12 at 12:37

1 Answers1

2

bing is changing their license system at the moment. this API was created using the "old" version 2 license. MS had done some changes when migrating to Azzure market place: https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44 migration guide: http://go.microsoft.com/fwlink/?LinkID=248077

I don't think that this is covered by this Java-API wrapper you use already.

someone
  • 21
  • 1