hi,
it is showing Service call failed: 404Not Found
pls help me
regards,
gayathri reddy
What I have tried:
Hi ,
This is my script to call wcf rest service
$(document).ready(function () {
$('#btnSubmit').click(function (event) {
debugger
event.preventDefault();
ValidateUser();
});
});
function ValidateUser() {
var request = '{"objUser":{"LoginID": "' + $('#sender-email').val() + '", "Password": "' + $('#user-pass').val() + '"}}';
// { u: { LoginID: $('#sender-email').val(), Password: $('#user-pass').val()} };
var jsondata = JSON.stringify(request);
Type = "POST";
Url = "http://localhost:25012/UserService.svc/AuthenticateUser/";
Data = jsondata,
ContentType = "application/json; charset=utf-8";
DataType = "json";
ProcessData = true;
// Call the Web Service....
CallLoginService();
}
// Declare Varibales which are using in AJAX method.
var Type;
var Url;
var Data;
var ContentType;
var DataType;
var ProcessData;
//Generic function to call WCF Service
function CallLoginService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
crossDomain: true,
success: function (msg) {
//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed // When Service call fails
});
}
function ServiceSucceeded(result) {
if (DataType == "json") {
resultObject = result.ValidateUserResult;
if (resultObject) {
var userdata = JSON.stringify(resultObject);
sessionStorage.userInforamtion = userdata;
window.location = "Index.html";
}
else {
alert("Invalid User");
$('#sender-email').val("");
$('#user-pass').val("");
}
}
else {
alert("Result Data type is not JSON");
}
}
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null;
}
Interface
[ServiceContract]
public interface IUserService
{
[OperationContract]
[WebInvoke(Method="POST", ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/AuthenticateUser")]
User ValidateUser(User objUser);
}
class
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class UserService : IUserService
{
public User ValidateUser(User objUser)
{
User _obj = new User();
MembershipUser u = Membership.GetUser(objUser.LoginID);
if (u != null)
{
if (u.IsApproved)
{
if (Membership.ValidateUser(objUser.LoginID, objUser.Password))
{
_obj.LoginID = objUser.LoginID;
_obj.UserID = 1;
}
else
{
_obj.Message = "LoginID/Password is in correct";
}
}
else
{
_obj.Message = "The Account has been inactivated";
}
}
else
{
_obj.Message = "LoginID does not exists";
}
return _obj;
}
}