//Code For Call WCF Service In WebForm <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script> <script type="text/javascript"> var Type; var Url; var Data; var ContentType; var DataType; function CallService() { $.ajax({ type: Type, //GET or POST or PUT or DELETE verb url: Url, // Location of the service data: Data, //Data sent to server contentType: ContentType, // content type sent to server dataType: DataType, //Expected data format from server success: function (msg) {//On Successfull service call ServiceSucceeded(msg); }, error: ServiceFailed// When Service call fails }); } function ServiceFailed(result) { alert('Service call failed: ' + result.status + '' + result.statusText); Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null; } function WCFJSON() { var id = "1"; Type = "GET"; Url = "http://localhost:52410/RestServiceImpl.svc/JSONData"; Data = '{"id"= "' + id + '"}'; // Data = {}; ContentType = "application/json; charset=utf-8"; DataType = "json"; CallService(); } function ServiceSucceeded(result) { if (DataType == "json") { resultObject = result.JSONDataResult; for (i = 0; i < resultObject.length; i++) { alert(resultObject[i]); } } } $(document).ready( function () { WCFJSON(); } ); </script> //Code In Web Config <system.serviceModel> <services> <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour"> <!-- Service Endpoints --> <!-- Unless fully qualified, address is relative to base address supplied above --> <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web"> </endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServiceBehaviour"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="web"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration> //Code In Wcf Service... //My InterFace IRestServiceImpl In Wcf Service!... [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped) ] string XMLData(string id); [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped) ] string JSONData(string id); } } //This Is InterFace Implementaion public class RestServiceImpl : IRestServiceImpl { public string XMLData(string id) { return "You requested product " + id; } public string JSONData(string id) { return "You requested product " + id; }
var Type;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)