I am having some issues with calling the asmx webservices that are installed by default when installing the wss 3.0 (Sharepoint 2007 I think) on the server.
Our sharepoint is using forms authentication. In IIS I can see the website and in that site the virtual directory "_vti_bin" exists (this is were the webservices are located.)
I can browse without problems to the WSDL, so I can add it to my web references in my visual studio solution (I used the "web reference" instead of "service reference" method to add the reference to my solution). I can't browse to the asmx webservice itself, it keeps redirecting to the login page.
In my code, I tried to use the Authentication asmx service, but I can't seem to consume it correctly..
This is my code:
protected Cookie _authCookie;
CookieContainer _cookieContainer;
using (Authentication spAuthentication = new Authentication())
{
spAuthentication.Url = "https://sharepointserverxx.com/_vti_bin/Authentication.asmx";
spAuthentication.CookieContainer = new CookieContainer();
//spAuthentication.AllowAutoRedirect = true;
spAuthentication.PreAuthenticate = true;
LoginResult loginResult = spAuthentication.Login(txtUser.Text, txtPassword.Text);
_authCookie = new Cookie();
if (loginResult.ErrorCode == LoginErrorCode.NoError)
{
CookieCollection cookies = spAuthentication.CookieContainer.GetCookies(new Uri(spAuthentication.Url));
_authCookie = cookies[loginResult.CookieName];
_cookieContainer = new CookieContainer();
_cookieContainer.Add(_authCookie);
return true;
}
else
txtResult.Text = "Invalid Username/Password while authenticating to the sharepoint webservices.";
return false;
}
I am getting the following error on the line with the following code:
LoginResult loginResult = spAuthentication.Login(txtUser.Text, txtPassword.Text);
Error: The request failed with the error message:
Object moved to < href="https://sharepointserverxx.com/_layouts/1033/error.aspx?ErrorText=Failed%20to%20Execute%20URL%2E">here
I think that my webservice call is always redirected to the login page of sharepoint.. Does anyone have an idea how I can fix this?
If I uncomment the following line, I get another error "Error: Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'." (because the response is the html page of the login page)
//spAuthentication.AllowAutoRedirect = true;