Click here to Skip to main content
12,945,927 members (37,163 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have written a WCF service to return a JSON response.However I coulnot get it ?
Here is my code:

IService.cs:
[OperationContract]
       [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;
        getappointmentlist.AppointmentList.Add(company);
    }
 
    return getappointmentlist;
}

web.config file:
<system.serviceModel>
    <services>
      <service name="Appointments.CompanyService" behaviorConfiguration="SampleCompSvcBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/SampleCompService"/>
          </baseAddresses>
        </host>
 
        <endpoint address="http://localhost:8732/SampleCompService/json" binding="webHttpBinding" contract="Appointments.ICompanyService" behaviorConfiguration="SampleCompSvcWebBehavior" bindingConfiguration="hk"/>

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
     </service>
   </services>
   <bindings>
     <webHttpBinding>
       <binding name="hk">
         <security mode="None"></security>
       </binding>
     </webHttpBinding>
   </bindings>
   <behaviors>
     <serviceBehaviors>
       <behavior name="SampleCompSvcBehavior">
 
         <serviceMetadata httpGetEnabled="True"/>
 
         <serviceDebug includeExceptionDetailInFaults="false"/>
       </behavior>
     </serviceBehaviors>
     <endpointBehaviors>
       <behavior name="SampleCompSvcWebBehavior">
         <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
       </behavior>
     </endpointBehaviors>
   </behaviors>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
 </system.serviceModel>


Where Am I going wrong ?
Posted 7-Sep-12 20:08pm
cutie1297
Updated 7-Sep-12 20:43pm
v2
Comments
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)

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 8 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100