Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to call service using json request
    primarykey
    data
    text
    <p>I am new to the WCF and writing my first WCF application. I am not able to call service from json request</p> <p>Following are the details of project/solution</p> <p>I have total 3 projects in my solution <img src="https://i.stack.imgur.com/yKGW2.jpg" alt="Solution Description"> 1. Service Library Project(MyFirstRESTfulService) 2. Host application(WCFService2) 3. Service Client(ServiceClient)</p> <p><strong>1. MyFirstRESTfulService</strong></p> <p>Class <strong>IEmployeeService.cs</strong></p> <pre><code>namespace MyFirstRESTfulService { [ServiceContract()] public interface IEmployeeService { [WebGet(UriTemplate = "Employee", ResponseFormat=WebMessageFormat.Json )] [OperationContract] List&lt;Employee&gt; GetAllEmployeeDetails(); } } </code></pre> <p>Class <strong>EmployeeService.cs</strong></p> <pre><code>namespace MyFirstRESTfulService { [AspNetCompatibilityRequirements(RequirementsMode= AspNetCompatibilityRequirementsMode.Allowed )] public class EmployeeService: IEmployeeService { public List &lt;Employee&gt; GetAllEmployeeDetails() { return EmployeeData.Instance.EmployeeList; } } } </code></pre> <p><strong>2. WCFService2</strong></p> <p><strong>Service.svc</strong></p> <p><strong>Web.config</strong></p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="false" targetFramework="4.0" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="MyFirstRESTfulService.EmployeeService"&gt; &lt;endpoint address="http://localhost:8046/WCFService2/Service.svc" behaviorConfiguration="Web" binding="webHttpBinding" contract="MyFirstRESTfulService.IEmployeeService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="http://localhost:8046/WCFService2/Service.svc/MyFirstRESTfulService/" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="Web"&gt; &lt;webHttp/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="false" /&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p><strong>3. ServiceClient</strong></p> <p>Default.aspx</p> <pre><code>&lt;body&gt; &lt;script src="Script/jquery1.9.0.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; jQuery.support.cors = true; function RefreshPage() { var serviceUrl = "http://localhost:8046/WCFService2/Service.svc/MyFirstRESTfulService/GetAllEmployeeDetails"; debugger; $.ajax({ type: "GET", url: serviceUrl, dataType: 'json', contentType: "application/json; charset=utf-8", success: function (data) { var itemRow = "&lt;table&gt;"; $.each(data, function (index, item) { itemRow += "&lt;tr&gt;&lt;td&gt;" + item.EmpId + "&lt;/td&gt;&lt;td&gt;" + item.Fname + "&lt;/td&gt;&lt;/tr&gt;"; }); itemRow += "&lt;/table&gt;"; $("#divItems").html(itemRow); }, error: ServiceFailed }); } &lt;/script&gt; &lt;/script&gt; &lt;form id="form1" runat="server"&gt; &lt;input type="button" onclick="RefreshPage()" name="btnRefesh" value="Refresh" /&gt; &lt;div id="divItems"&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>But these things not working at all.While clicking on button nothing is happening.Can you please tell me where I went wrong.</p> <p>I am getting following error</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Service&lt;/title&gt; &lt;style&gt;BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}&lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="content"&gt; &lt;p class="heading1"&gt;Service&lt;/p&gt; &lt;p&gt;Endpoint not found.&lt;/p&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks in Advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload