I am trying to get my jquery code to work with WCF. I start with something very simple. WCF is hosted in IIS. It has a simple interface and simple implementation. Below is my WCF code.
[ServiceContract] public interface IEvalService { [OperationContract] [WebInvoke(Method = "GET", UriTemplate = "GetId", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string GetId(); }
The implementation of the above interface is as follows:
[AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Allowed)] public class EvalService: IEvalService { public string GetId() { BenchMarkStatus benchMarkStatus = new BenchMarkStatus(); return benchMarkstatus.Name; } }
Of course, there is a benchMark class as follows:
[DataContract] public class BenchMarkStatus { private string _name; public BenchMarkStatus() { _name = "Sudarshan"; } [DataMember] public string Name { get { return _name; } set { _name = value; } } }
The configuration file for the Webservice is as follows:
<services> <service name="BenchMarkServiceLiabrary.EvalService"> <endpoint address="10.66.26.171" binding="webHttpBinding" contract="BenchMarkServiceLiabrary.IEvalService" behaviorConfiguration="WEB" /> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="WEB"> <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json"/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
And on the client side, I have the following code:
$.ajax({ type: 'GET', url: "http://10.66.26.171/EvalService/Eval.svc/GetId?callback=?", contentType: "json/application; charset=utf-8", dataType: "jsonp", jsonpCallback: 'jsonCallback', success: function (data) { alert(data) } }); function jsonCallback() { alert("me"); }
I get error 404. Initially, I had problems with Cross domain stuff ... but now, using the client code, you cannot access the GetId function. Can anybody help?