Search Web Service not working in SharePoint 2007

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

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load
Try

Dim keywordStringAsString ="Microsoft"
Dim qXMLStringAsString ="<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 queryServiceAs QueryService =New QueryService()
queryService.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim queryResultsAs DataSet =New DataSet

queryResults = queryService.QueryEx(qXMLString)

Catch exAs Exception

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

EndTry

EndSub

End

Class

Please let me know, if you encounter similar errors.

Thanks

John

[3738 byte] By [JohnDeBritto] at [2008-2-6]
# 1
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

Jagad at 2007-9-6 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Search...
# 2
Try to give custom credentials from a user who has sufficant rights on the WSS site.
use this code:
Dim queryService As QueryService = New QueryService()
queryService.Credentials = new System.Net.NetworkCredential()
queryService.Credentials.UserName = ConfigurationManager.AppSettings("WSSUser") 'Or username as string
queryService.Credentials.Password = ConfigurationManager.AppSettings("WSSPwd") 'Or pwd as string
queryService.Credentials.Domain = ConfigurationManager.AppSettings("WSSDom")
'Or domain as string

Then your authentication will succeed

TheRave at 2007-9-6 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Search...
# 3
Did you ever get this working. I have the same issue. I am running with an account that has sufficient permissions (administrator) so that is not the issue.
DanClash at 2007-9-6 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Search...
# 4

I had kind of similar issue. You can try two things:

1. Try to test this in a Kerberos environment.

2. In the environment where I had to deploy my web application that called search web service, when I used the same account for my web application's app pool as it was for Sharepoint application's app pool, the error disappeared.

one447 at 2007-9-6 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Search...
# 5
Do anybody share his solution for this issue?
ZhaoPingLi at 2007-9-6 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Search...

SharePoint Products and Technologies

Site Classified