Search Web Service not working in SharePoint 2007

Last post 03-13-2007 7:48 AM by TheRave. 2 replies.

Sort Posts:

  • Search Web Service not working in SharePoint 2007

    03-06-2007, 7:54 AM

    Hi,

     I am trying to access the web service provided by sharepoint 2007 and use it in the ASP.NET application. I want to use the following Web Service.

     http://localhost/_vti_bin/search.asmx

    http://localhost/_vti_bin/spsearch.asmx

    And while executing the code, following error is being thrown.

    Server was unable to process request. ---> Attempted to perform an unauthorized operation.

    Following is the code I am using to access the Web Service.

    Imports

    SPSSearch
    Imports System.Data

    Partial

    Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Try

              Dim keywordString As String = "Microsoft"
              Dim qXMLString As String = "<QueryPacket xmlns='urn:Microsoft.Search.Query'><Query><SupportedFormats><Format revision='1'>urn:Microsoft.Search.Response.Document:Document</Format></SupportedFormats><Context><QueryText language='en-US' type='STRING'>" + keywordString + "</QueryText></Context></Query></QueryPacket>"

              Dim queryService As QueryService = New QueryService()
              queryService.Credentials = System.Net.CredentialCache.DefaultCredentials
              Dim queryResults As DataSet = New DataSet

              queryResults = queryService.QueryEx(qXMLString)

    Catch ex As Exception

              Response.Write(ex.Message.ToString())

    End Try

    End Sub

    End

    Class

     Please let me know, if you encounter similar errors.

    Thanks

    John

  • Re: Search Web Service not working in SharePoint 2007

    03-09-2007, 6:37 AM
    • Member
      17 point Member
    • acacjag
    • Member since 10-12-2006, 5:43 AM
    • Posts 11

    You should set the URL for the Queryservice object and set QueryService.PreAuthenticate=true

    Please find the below code and change the queryService.Url if you'r conecting remote server.
    Code:
            //The string containing the keyword to use in the search
            string keywordString = TextBox1.Text;
            //The XML string containing the query request information
            //for the Web service
            string qXMLString = "<QueryPacket xmlns='urn:Microsoft.Search.Query'>" +
            "<Query><SupportedFormats><Format revision='1'>" +
            "urn:Microsoft.Search.Response.Document:Document</Format>" +
            "</SupportedFormats><Context><QueryText language='en-US' type='STRING'>" +
            keywordString + "</QueryText></Context></Query></QueryPacket>";

            SPSearch.QueryService queryService = new SPSearch.QueryService();
            queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
            queryService.PreAuthenticate = true;
            queryService.Url = "http://localhost/_vti_bin/spsearch.asmx";
            System.Data.DataSet queryResults = queryService.QueryEx(qXMLString);
            GridView1.DataSource = queryResults.Tables[0];
            GridView1.DataBind();

     
    Thanks&Regards,
    Jagad

  • Re: Search Web Service not working in SharePoint 2007

    03-13-2007, 7:48 AM
    • Member
      4 point Member
    • TheRave
    • Member since 01-08-2007, 9:40 AM
    • Posts 2

    Hi,

    I got the webservice working.

    But I'm having a very hard time to filter my search.

    I want to for example get documents that belong to a certain document library and search on custom properties.

    I can't figure out how to do it. I tried using the SQL query syntax but I only manage to retrieve the documents I want:

     

    StringBuilder sb = new StringBuilder();

                sb.Append("<QueryPacket xmlns='urn:Microsoft.Search.Query'><Query>");
                sb.Append("<SupportedFormats><Format revision='1'>urn:Microsoft.Search.Response.Document:Document</Format>");
                sb.Append("<Format revision='1'>urn:Microsoft.Search.Response.Content:Content</Format>");
                //sb.Append("</SupportedFormats><Context><QueryText language='en-US' type='STRING'>new</QueryText></Context>");
                sb.Append("</SupportedFormats><Context><QueryText type='MSSQLFT' language='en-us'>select path,title,size,write,\"urn:schemas-microsoft-com:office:office#ows_ListTemplate\", \"DAV:iscollection\",IsDocument, displaytitle, description, \"DAV:getcontenttype\", rank from scope() where size > 0 and freetext('" + _searchQuery + "') and IsDocument like '1'-- </QueryText></Context>");
                sb.Append("<Range><StartAt>1</StartAt><Count>100</Count></Range>");
                sb.Append("<Properties></Properties><SortByProperties><SortByProperty name='IsDocument' direction='Ascending'/></SortByProperties>");
                sb.Append("</Query></QueryPacket>");



                SPSSearch.QueryService qWSSsearch = new SPSSearch.QueryService();
                qWSSsearch.Credentials = G4SCommon.GetCredentials();

    This query works fine, but it returns to much information, I want to narrow the saerch to a certain document library and even to the contents of some custom fields.

    If I trie to use these custom fileds I get an error. Has someone doen this before? Or does anyone has examples of complicated searches with WSS 3.0?

    I got lots of code from SPS 2003, but it is not applicable anymore. 

     

Page 1 of 1 (3 items)