dimanche 28 juin 2015

Rest method in wcf service

I want to create method in my WCF service that will return json.

Service code:

public interface IParseService
{
    [OperationContract]
    IList<SocialEventDto> GetSocialEvents(int pageNumber = 1);

    [OperationContract]
    [WebGet(UriTemplate = "/socialevents/{pageNumber}",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    IList<SocialEventDto> GetSocialEventsJson(string pageNumber);

    [OperationContract]
    IList<ServiceOptionDto> GetServiceOptions();
    //some other methods...
}

web.config:

<system.serviceModel>
    <services>
        <service name="ParserWebRole.ParseService">
        <endpoint address=""
                  binding="webHttpBinding"
                  behaviorConfiguration="webBehavior"
                  contract="ParserWebRole.IParseService"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

When I try to invoke

http://localhost:18549/ParseService.svc/socialevents/1 

I get

This webpage is not available

What am I doing wrong?

I saw similar questions but none of them help me.

Aucun commentaire:

Enregistrer un commentaire