WCF with REST full Service [Resolved]

Posted by Allemahesh under WCF on 12/5/2013 | Points: 10 | Views : 2330 | Status : [Member] [MVP] | Replies : 7
I am using WCF REST full service. I have created the service and consumed in my application.

WCF REST Service:- http://www.topwcftutorials.net/2013/09/Simple-Steps-For-RESTful-Service.html

Web Application:- http://www.c-sharpcorner.com/UploadFile/81a718/consume-restful-service-using-jquery-in-two-simple-steps/

This is working file in IE but not working in Mozilla and chrome.
Can any one help me to sort this issue?




Responses

Posted by: Allemahesh on: 12/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down

Resolved
Finally got the solutions to my problem.
Here is the link:-
http://blog.weareon.net/calling-wcf-rest-service-from-jquery-causes-405-method-not-allowed/

Solutions:-

Add Global.asax file to the WCF REST project and update Application_BeginRequest method with this snippet.

protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}


Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
What problem you are getting in mozilla? Please explain.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/5/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Below is my code:-

<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost/Service1.svc/GetProductList/",
dataType: "xml",
success: function(xml) {
$(xml).find('Product').each(function() {
var id = $(this).find('ProductId').text();
var name = $(this).find('Name').text();
var price = $(this).find('Price').text();
var category = $(this).find('CategoryName').text();

$('<tr><td>' + id + '</td><td>' + name + '</td><td>' + price + '</td><td>' +
category + '</td></tr>').appendTo('#products');
});
},
error: function(xhr) {
alert(xhr.responseText);
}
});
});
</script>


When I run the above code in my Mozilla or chrome, I am getting the empty alert box.
Can you help me?

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/5/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Vishal,

Have you got solutions?

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please debug your code
write debugger inside below $(document).ready(function() {
function

and debug it.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/5/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please,download add-ins error console from below links:-
https://addons.mozilla.org/En-us/firefox/addon/error-console/

it will show error.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 12/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Empty message. Any help?

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response