I am trying to use custom webservice deployed on SharePoint server. I have added proxy class for WebService in my project.
I am passing correct credentials to connect to WebService call, when I am trying to invoke method from WebService class, it is redirecting to Login page and sending HTML Code in response for login page.
//Code for using webservice
var webServiceObj = new MyWebService();
webServiceObj.Credentials = new NetworkCredential(Constants.UserName_Cridentials, Constants.Password_Cridentials, Constants.DomainName_Cridentials);
var result = webServiceObj.GetWeekReport(ID, Date);
Thanks, Nikhil.
It looks like your SharePoint Server Web Application has Forms Based Authentication. When you define webServiceObj.Credentials you will use Windows Authentication, while the service expects Forms Based.
To call service in your Authentication scenario you need:
Call Authentication.asmx web service to get CookieContainer
Assign CookieContainer to your webServiceObj.CookieContainer
Call service
I found this article that describes it perfectly http://www.tonytestasworld.com/post/2009/06/04/How-To-Authenticate-and-Use-SharePoint-Web-Services-in-an-FBA-SharePoint-site.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.