WCF Service encoding single quotes after upgrade to Server 2019

174 Views Asked by At

After upgrading our webserver to Windows 2019 (from 2008) our WCF service (.NET 3.5) responses are html encoded. For clarification, the response is supposed to be an encoded xml string (intentionally, via System.Web.HttpUtility.HtmlEncode) - but after the upgrade it appears the response is getting encoded twice. Here's an example:

Old response before server upgrade (notice the single quotes on ResultName are not encoded):

<a:ResultData><![CDATA[&lt;Result&gt;&lt;schema&gt;&lt;ts name='ResultName' … </a:ResultData>

New response after server upgrade (the single quotes are encoded)

<a:ResultData><![CDATA[&lt;Result&gt;&lt;schema&gt;&lt;ts name=&#39;ResultName&#39; … </a:ResultData>

Is there any IIS setting we may have missed that would cause this behavior? or some WCF specific behavior that we need to enable/disable? I've looked around online and haven't found any info specific to this problem yet. Given that the code itself has not changed and it used to work, we are looking at the server configuration to provide the answer, but haven't found the culprit.

Thanks for any assistance!

1

There are 1 best solutions below

0
On

The issue is in the version of System.Web.HttpUtility.HtmlEncode.

System.Web v2 does not encode single quotes but System.Web v4 does.

Unfortunately we did not setup our Application Pools on our new server and the WCF service was running in a newer version of .NET which loaded a newer version of System.Web v4 which encoded the single quote.

Once the WCF service was assigned the correct App Pool the problem was resolved.