Thursday, 4 August 2016

Creating Rest Service - WCF

Create WCF Project


1. In Interface


namespace ServiceWCF
{
   
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebGet(UriTemplate = "/loginURL?uid={idval}&pass={Pwdval}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
        string LCheck(string idval, string Pwdval);

     }

}




2.Then Service.svc file
  public string LCheck(string id, string Pwd)
        {
           return "some value";
        }




3.ENABLE HTTP

<%@ ServiceHost Language="C#" Debug="true" Service="ServiceWCF.Service" %>



in Web.config

<?xml version="1.0"?>
<configuration>
 
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
       
      <service behaviorConfiguration="beh" name="ServiceWCF.Service">
        <endpoint address="" behaviorConfiguration="webby" binding="webHttpBinding"
          bindingConfiguration="" contract="ServiceWCF.IService1" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior  name="beh">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webby">
          <webHttp/>
          
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  
</configuration>



No comments:

Post a Comment