Tag Archives: .net

WCF config to avoid content-length error

Low quality blog post. This is a personal note/reminder.

I quickly post here a reference WCF config file to avoid the content-lenght error when uploading some content.

The key config section here was <system.webServer></system.webServer>

<?xml version="1.0" encoding="utf-8"?>
 <!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1"/>
    <httpRuntime targetFramework="4.5.1" maxRequestLength="50000"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="SchedulerWSServiceBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
                 allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2000000" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="W.Scheduler">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SchedulerWSServiceBinding" contract="Web.Services.IScheduler"/>
      </service>
    </services>
    <client>
      <endpoint address="http://localhost/W/Scheduler.svc" binding="basicHttpBinding" bindingConfiguration="SchedulerWSServiceBinding" contract="Web.Services.IScheduler" name="WSClientScheduler"/>
    </client>
  </system.serviceModel>
  <system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="50000000" />    <!-- Allow files of upto 50,000,000 bytes (about 50Mb) to be uploaded -->
    </requestFiltering>
  </security>
</system.webServer>
</configuration>

.Net Core basics

Microsoft is pushing hard with .NET Core and everyone can see that they are very proud of it. I never gave too much attention to it but now it’s time. So I started from scratch.

What is .NET Core?

.NET Core is a cross-Platform free and open-source managed software framework – Wikipedia

NET Core is a blazing fast, lightweight and modular platform for creating web applications and services that run on Windows, Linux and Mac. – Microsoft

.NET Core 2.0 implements the .NET Standard 2.0. The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET implementations.

Immagine

Install

.Net Core 2.0 (https://aka.ms/dotnet-sdk-2.0.0-win-gs-x64)

Create some code

Open console and type:

> dotnet new console -o HelloCore
> cd HelloCore

dotnet is the base command of the SDK and it has many features like testing, nuget functionalites, managing dependencies and otheres. The new command is used to initialize new applications and we specify a console application and we want that application in the HelloCore directory. cd HelloCore moves into the newly created app directory.

View the code

With our favourite text editor we open Program.cs and we see that dotnet new has created a simple hello world app.

using System;

namespace HelloCore
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Run

With the

> dotnet run

command we launch our first .Net Core app.

> Hello World!

TL; DR

.NET Core is a brand new implementation of .NET and it’s the multi-platform component of the .NET family.

With this blog post we explored the basic concepts of .Net Core. We also created our first app in 5 minutes.