Click here to Skip to main content
15,799,257 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have written a WCF service to return a JSON response.However I coulnot get it ?
Here is my code:

       [WebInvoke(UriTemplate = "GetAppointments/?companyId={companyId}&appointmentDate={appointmentDate}", Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
     GetAppointmentList GetAppointment(Guid companyId, string appointmentDate);

Service1.cs :
public GetAppointmentList GetAppointment(Guid companyId, string appointmentDate)
    SQLDataContext context = new SQLDataContext();
    var getappointment = context.GetAppointmentTimings(companyId,appointmentDate);
    GetAppointmentList getappointmentlist = new GetAppointmentList();
    getappointmentlist.AppointmentList = new List<company>().ToList();         
    foreach (var r in getappointment.ToList())
        Company company = new Company();
        company.CompanyId = r.CompanyId;
        company.CompanyName = r.CompanyName;
        company.BreakStartTime = r.BreakStartTime + ":" + "00";
        company.BreakEndTime = r.BreakEndTime + ":" + "00";
        company.Interval = r.Interval;
        company.AppointmentStartTime = r.AppointmentStartTime;
        company.AppointmentEndTime = r.AppointmentEndTime;

    return getappointmentlist;

web.config file:
      <service name="Appointments.CompanyService" behaviorConfiguration="SampleCompSvcBehavior">
            <add baseAddress="http://localhost:8732/SampleCompService"/>

        <endpoint address="http://localhost:8732/SampleCompService/json" binding="webHttpBinding" contract="Appointments.ICompanyService" behaviorConfiguration="SampleCompSvcWebBehavior" bindingConfiguration="hk"/>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       <binding name="hk">
         <security mode="None"></security>
       <behavior name="SampleCompSvcBehavior">

         <serviceMetadata httpGetEnabled="True"/>

         <serviceDebug includeExceptionDetailInFaults="false"/>
       <behavior name="SampleCompSvcWebBehavior">
         <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

Where Am I going wrong ?
Updated 29-Sep-20 12:28pm
Member 10656177 23-Mar-14 23:35pm    
Did you find a solution to this? I have the same problem. I wonder if its to do with using a Class file (*.cs) rather than the Service file (*.svc)

1 solution

What sort of error are you getting? Without knowing what the error is it is somewhat hard to interpret. Is the service even starting? If the service is starting I would recommend seeing if the "help" section will display.

If the service starts ok, then I would recommend changing the "includeExceptionDetailInFAults=false" to true to see if it will display the error for you until you can figure out what is going wrong. I would also reccomend adding nLog for logging if you haven't done so already. It helped me tremendously with getting things up and going.
Share this answer
Dave Kreskowiak 29-Sep-20 20:47pm    
I seriously doubt the OP is working on this 8 years later.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900