-2

I created wcf JSON rest service for windows application using C# and it has some methods.Now i want to call the one of the method from javascript using $.getJSON function. how can i call it. Please give me suggestions

1 Answers1

0

You can use the below syntax.

$.getJSON({
url:"http://localhost:26850/Service1.svc/HelloWorld?",
data: '{"Name":"Testing"}',
success:fnsuccesscallback
});

Also make sure that <enableWebScript/> is configured in the end point bahaviour to enable the wcf service to be called from javascript.

Saranya
  • 1,988
  • 16
  • 20
  • is that a cross domain request?i mean is the webapplication and wcf hosted under same origin? when the protocol, domain or portnumber differs it is a cross origin request and you have to use jsonp – Saranya Nov 05 '13 at 12:16
  • how to use that jsonp give me example – user2955607 Nov 05 '13 at 12:24
  • JSONP is just json wrapped inside a js method. you send the method name as a callback parameter on the querystring which the server side code will use to wrap the json in and send the response back. there are lot of examples out in this site on jsonp.http://stackoverflow.com/questions/2681466/jsonp-with-jquery/2686406#2686406 – Saranya Nov 05 '13 at 12:30
  • the web application has a virtual directory. when i used the Json function and browse the html page from the iis i am getting the url "http://localhost/rupeshwebsite/RJ.htm" this url is working fine in IE and displaying the data in browser. but when i paste the same url in chrome or firefox it does not displaying any data why? – user2955607 Nov 05 '13 at 12:38