Buscar contenidos

jueves, 26 de julio de 2018

How to Create / Convert WCF service into REST service C# .NET


    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(Method="POST", ResponseFormat=WebMessageFormat.Json)]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }



<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
     
     
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
   
      <!--INICIO 1.*******************-->     
      <!--Algregar en el método de la Interface-->            
      <!--FIN 1.*******************-->
              
      <!--INICIO 2.*******************-->
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>     
      </endpointBehaviors>
      <!--FIN 2.*******************-->
     
                             
    </behaviors>
           
    <!--INICIO 3.*******************-->
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" > </serviceHostingEnvironment>     
    <!--FIN 3.*******************-->

  
    <!--INICIO 5.*******************-->
    <services>   
      <service name="WcfServicePruebaSoapRest.Service1">
            <endpoint binding="webHttpBinding" contract="WcfServicePruebaSoapRest.IService1" behaviorConfiguration="web">  </endpoint>
          <endpoint binding="basicHttpBinding" contract="WcfServicePruebaSoapRest.IService1" address="soap" />
      </service>
    </services>
    <!--FIN 5.*******************-->
  
   
     
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>   
   
    <!--INICIO 4.**********(ocultar)*********-->
      <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
    <!--INICIO 4.*******************-->
     
  </system.serviceModel>
 
   
   
   
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>




No hay comentarios:

Publicar un comentario