Here You have defined one parameter in your template url & method in service Contract.
public interface IService
{
[OperationContract]
[WebInvoke(UriTemplate = "/Welcome/{Name}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
string Welcome(string Name);
}
First Check Your JavaScript function is being called or not.
You are not passing any parameter in your ajax call.
And Your Ajax call should be like this...
var YourData = "/&Hello";
$.ajax({
type: "GET",
contentType: "application/json;charset=utf-8",
url: 'http://localhost:49485/WCFRestService.svc/SayHelloWorld?callback=?' + YourData,
dataType: "jsonp",
jsonpCallback: "MyCallBack",
success: MyCallBack,
error: function () {
alert("error");
}
});
function MyCallBack(data) {
alert('success : ' + data);
}
And Your Responce data should be wrapped like MyCallback({YourjsonData}).
In Your WCF service write your Responce like this.
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/json";
string callback = HttpContext.Current.Request.QueryString["callback"];
HttpContext.Current.Response.Write(callback + "( " + new JavaScriptSerializer().Serialize(YourListObjectGoesHere) + " )");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
Hope This Helps You.
------------------------
Pratik Bhuva.