6

I am running an ASP.Net app on Windows Server 2008 R2. I have up to .NET Framework 4.5 installed. Upon migrating from .NET Framework v2.0 to v4.0 I began to experience random behavior from WCF.

My web service returns JSON. Upon restarting IIS the service will return perfectly valid JSON about 3 to 5 times. After that, the JSON becomes invalid. I have inspected what is coming across the wire via Fiddler and also my own logs on both client app (an Adobe AIR app that calls the service) and on the server itself.

Fiddler shows that the raw response does in fact contain invalid JSON. It appears very much that a some random point in the JSON the response JSON begins to get written out again!, overwriting what should be there and producing mangled JSON in the process.

See this concatenated example:

{"responseCode":0,"actionCode":"OK","cdn{"responseCode":0, "actionCode".....

Note how "responseCode" (which should only appear at the beginning of the JSON response) suddenly appears again in the JSON further on. "cdn{"responseCode":0 is of course invalid JSON.

I have tried numerous patches. I've tried running ServiceModelReg.exe and aspnet_regiis.exe from under different frameworks and in different combinations. Same behavior. If I revert to previous code under v2.0 and switch the App Pool back to v2.0 then everything works fine.

I believe this to be a bug deep in WCF. Any ideas?

The only recourse I have at this point is to rip out WCF and switch to something like ServiceStack where I can debug into all the code if necessary.

simbolo
  • 7,279
  • 6
  • 56
  • 96
Kevin MacDonald
  • 650
  • 8
  • 21
  • 1
    Looks like some sort of buffering problem, where a buffer is retransmitted, or where a buffer isn't cleared after transmission/reception. – Hot Licks Nov 07 '12 at 01:35
  • 4
    I am not aware of any existing issues on this. But it would be helpful to understand if you can post a piece of repro code. – Praburaj Nov 07 '12 at 15:58
  • Have you tried FailedRequestLogging to see if there's anything fishy going through the process? Have you tried running your return objects through the JavaScriptSerializer() to see if there's a glitch in it? You can debug into the framework if you need to (see: http://msdn.microsoft.com/en-us/library/cc667410.aspx). – Pete Dec 21 '12 at 20:40
  • Are you using some custom message inspectors (IDispatchMessageInspector) or anything like that that could mangle the response? – jhexp Feb 11 '13 at 09:35
  • did you also try SvcTraceViewer.exe http://msdn.microsoft.com/en-us/library/ms732023.aspx)? – evgenyl Apr 14 '13 at 05:18
  • I bet the part of the response that is invalid begins at the 128th character. Yes? We are seeing this same behavior with an ODATA service, it is outputting invalid xml. The first 128 characters are repeated in place of the 2nd 128 characters. Removing the diagnostics section in web.config as mentioned in one of the answers fixed it. There must be a bug in whatever that is doing that isn't handling buffers correctly. – InfinitiesLoop Jun 25 '13 at 21:10

2 Answers2

1

Had the exact same problem. I fixed this by removing these 2 entries from my web.config:

<system.serviceModel>
    <diagnostics>
        <messageLogging logEntireMessage="true" logMessagesAtTransportLevel="true" maxSizeOfMessageToLog="-1" maxMessagesToLog="-1" />
    </diagnostics>
</system.serviceModel>

and

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="messages" type="MyCustomListener" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>
Mark
  • 473
  • 6
  • 7
  • Some of the solutions and comments above might have worked. I don't know. My final solution was to abandon WCF and use Service Stack. So far I am finding it is a superior architecture for implementing web services. – Kevin MacDonald Dec 25 '13 at 05:46
0

Are you setting InstanceContextMode to Single/PerSession?

Refer this... Mix up two responses

Community
  • 1
  • 1
Rajes
  • 1,036
  • 10
  • 15