Create your own WCF is quite easy. It’s also easy run it within Visual Studio and debug it, but when you need to put it online, how can you proceed? After you install it on IIS, you must configure it. Here a web.config file, ready to be used.

This config allows you to:

  1. receive cors request
  2. access a database through Entity Framework
  3. enable http and https
  4. use the max dimension for output data
  5. rest environment

 

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="myVaueLabel1" value="myValue1"/>-->
    <add key="ClientSettingsProvider.ServiceUri" value="" />
    <add key="myValueLabel2" value="myValue2" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="NamespaceName.ServiceName">
        <endpoint address="" behaviorConfiguration="restBehavior" binding="webHttpBinding" name="base" contract="NamespaceName.ServiceName">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="SecurityByTransport" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <extensions>
      <behaviorExtensions>
        <add name="CorsSupport" type="WebHttpCors.CorsSupportBehaviorElement, WebHttpCors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <!--<enableWebScript/>-->
          <webHttp helpEnabled="true" />
          <CorsSupport />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="123456" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/AccessData.Model.csdl|res://*/AccessData.Model.ssdl|res://*/AccessData.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=127.0.0.1\SQLexpress;initial catalog=myDB;persist security info=True;user id=sa;password=1234;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
Advertisements