UPDATE 3
var local = \'http://localhost:1163/CustomerService.svc/getcustomer?method=?\';
var dev = \'http://yourserver.com/CustomerService.svc/GetCus
In the provided sample application (JSONP) the service method is called GetCustomer
and not GetLocation
. So to call it:
http://localhost:1163/service.svc/getcustomer?method=jsoncallback
which returned the following response in my browser:
jsoncallback( {"Address":"1 Example Way","Name":"Bob"} );
The reason that Visual Studio Intellisense underlines the
is because this is a custom binding element and not part of the schema and it is not known. You can safely ignore this warning.
The only problem with this sample is that the files are packaged in a Class Library instead of Web Application. In order to run the service more easily in the Visual Studio built in server you could create a new Web Application, copy all the files to this new application and run it. You just need to modify this line in web.config:
^
to include your web application name:
^
That's all. Now go ahead and write a client application which consumes this JSONP stream. jquery does a great job with the $.getJSON() method:
$.getJSON('http://localhost:1163/service.svc/getcustomer?method=?', function(customer) {
alert(customer.Address);
});
I have uploaded my working version here.