Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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;
}
}
Posted
Updated 25-Jun-16 10:28am
Comments
Afzaal Ahmad Zeeshan 25-Jun-16 7:49am    
Your resource may not be available at that URL. Double check the URL and then try again.
Gayathri Reddy 27-Jun-16 3:39am    
thanx ahmad.now the url link is working fine
Karthik_Mahalingam 25-Jun-16 11:50am    
paste the url in the browser address bar and check whether it is hitting the service method.
Gayathri Reddy 27-Jun-16 3:40am    
thanx karthik.now the url is hit the service via ajax call
Karthik_Mahalingam 27-Jun-16 3:44am    
Cool

1 solution

404 means a resource that you are trying to access cannot be found. In your case, the URL path of your service is invalid or it doesn't exist or cannot be found.

You should revisit your code and use the correct URL path of your service. As mentioned by members, you can try browsing the URL of your service and see if it's accessible.

You can also refer this article about the various ways to communicate with your database using jQuery: http://www.mikesdotnetting.com/article/104/many-ways-to-communicate-with-your-database-using-jquery-ajax-and-asp-net[^]
 
Share this answer
 
Comments
Gayathri Reddy 27-Jun-16 3:42am    
thanx vincent.actually i did mistakes in passing parameter in URL.now the source is avail in that link.
Vincent Maverick Durano 27-Jun-16 15:46pm    
Awesome! Please dont forget to close this thread if your issue was resolved. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900