'Replaced DataContractJsonSerializer with Newtonsoft JsonSerializer and it is still using DCJS
I have an old project that is serializing TimeSpans like "PT21H", this is happening because DCJS is the default serializer for the project, I assume. I tried to implement the instructions here. But, when I hit the endpoint it is still returning the object serialized using DCJS with the Timespan looking like "PT21H"I don't want to overload this with all of my code so I will include what I believe is useful but feel free to ask for more information.
Relevant section of Web.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
    
  <system.web>
      <compilation debug="true" targetFramework="4.8" />
      <httpRuntime targetFramework="4.5.1" />
  </system.web>
    
    
  <system.webServer>
      <asp scriptErrorSentToBrowser="true" />
      <modules runAllManagedModulesForAllRequests="true">
          <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </modules>
  </system.webServer>
    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <extensions>
            <behaviorExtensions>
                <add name="newtonsoftJsonBehavior" type="Test.WcfNewtonsoftJsonSerializer.NewtonsoftJsonBehaviorExtension, Test, Culture=neutral" />
            </behaviorExtensions>
        </extensions>
        <behaviors>
            <endpointBehaviors>
                <behavior name="restEndPointBehavior">
                    <webHttp helpEnabled="false" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" faultExceptionEnabled="false" />
                    <newtonsoftJsonBehavior />
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="restServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="Test.WebserviceAscent.Webservice" behaviorConfiguration="restServiceBehavior">
                <endpoint address="" behaviorConfiguration="restEndPointBehavior" binding="webHttpBinding" bindingConfiguration="restWebHttpBinding" contract="Test.Web.IWebservice" />
            </service>
        </services>
        <bindings>
            <webHttpBinding>
                <binding name="restWebHttpBinding" contentTypeMapper="Test.WcfNewtonsoftJsonSerializer.NewtonsoftJsonContentTypeMapper, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
                </binding>
            </webHttpBinding>
        </bindings>
    </system.serviceModel>
  </location>
  <runtime>
...
  </runtime>
</configuration>
I have included the same files as the example, I even kept the same namespace for them:

What am I doing wrong?
I looked at a similar post here, but I couldn't get it to work. Are these solutions simply outdated and there is a better way to do this?
Edit: Here is my testcode that is having the same problem: https://github.com/JasonRAndersen00/SerializerTest
Solution 1:[1]
I found the problem with my web.config. It is such a newb mistake I am honestly tempted to not say anything. I was putting the wrong namespaces on the service.
<service name="Test.WebserviceAscent.Webservice" 
Should be
<service name="Test.Web.Webservice" 
Because of this it just wasn't assigning the serializer to my endpoints.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Jason Andersen | 
