title: Java using SharePoint 2010 Web Services - SPSearch.asmx
body: <p>I'm developing a custom component in Java (1.7).
  This component needs to be able to Push and Pull a file to a SharePoint 2010 Server.</p>
  
  <p>I've successfully Pushed a file along with metadata to the Server.
  I've also successfully Pulled a file from the Server.</p>
  
  <p>Well I need to be able to search (query) the Server depending on different search criteria according to what the User feeds my component. </p>
  
  <p>I've been unable to successfully connect to the SPSearch Web Service.</p>
  
  <p>I get this error:</p>
  
  <p>"Error caught in main: javax.xml.ws.WebServiceException: {<a href="http://microsoft.com/webservices/SharePoint/QueryService" rel="nofollow">http://microsoft.com/webservices/SharePoint/QueryService</a>}QueryServiceSoap is not a valid service. Valid services are: {<a href="http://schemas.microsoft.com/sharepoint/soap/" rel="nofollow">http://schemas.microsoft.com/sharepoint/soap/</a>}Lists
  "</p>
  
  <p>I've searched on Google endlessly and found some C# code that I was able to teach myself how I need to use the service, but it doesn't help me utilize the service successfully. I cannot find a good Java reference to utilize this web service.</p>
  
  <p>Any help or suggestions would be greatly appreciated. Thank you.</p>
  
  <p>(wsdl = SPURL/_vti_bin/spsearch.asmx?wsdl; endpoint = SPURL/_vti_bin/spsearch.asmx)</p>
  
  <p>Here's the Code:</p>
  
  <pre><code>protected ListsSoap getListsSoap(String username, String password, String wsdl, String endpoint) throws Exception {
      System.out.println("Creating a ListsSoap instance...");
      Lists service = new Lists(new URL(wsdl), new QName("http://schemas.microsoft.com/sharepoint/soap/", "Lists"));
      ListsSoap port = service.getListsSoap();
      BindingProvider bp = (BindingProvider) port;
      bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
      bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
      bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
      return port;
  }
  
  protected CopySoap getCopySoap(String username, String password, String wsdl, String endpoint) throws Exception {
      System.out.println("Creating a CopySoap instance...");
      Copy service = new Copy(new URL(wsdl), new QName("http://schemas.microsoft.com/sharepoint/soap/", "Copy"));
      CopySoap copySoap = service.getCopySoap();
      BindingProvider bp = (BindingProvider) copySoap;
      bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
      bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
      bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
      return copySoap;
  }
  
  protected QueryServiceSoap getQuerySoap(String username, String password, String wsdl, String endpoint) throws Exception {
      System.out.println("Creating a QuerySoap instance...");
      QueryService service = new QueryService(new URL(wsdl), new QName("http://microsoft.com/webservices/SharePoint/QueryService", "QueryServiceSoap"));
      QueryServiceSoap querySoap = service.getQueryServiceSoap();
      BindingProvider bp = (BindingProvider) querySoap;
      bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
      bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
      bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
      return querySoap;
  }
  </code></pre>