Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This program has 2 components:
A. an HTML page containing
A1. an <IFrame> that contains an <input type="file"... />
A2. javascript running in the containing page that is on a timer to make a jQuery .getAjax call once per second.
B. a Wcf Service that is contacted by the javascript every second.

The file uploads to an MVC3 Controller action:
public void UploadImage(HttpPostedFileBase image)
This action method reads the data in 100kb chunks, and updates a Percent Complete statistic in a singleton Hashtable (or Dictionary).

The accompanying Wcf Service (#2 above) returns the statistic as JSON.

PROBLEM:
After a fresh deployment, everything works. I can upload a file from two different browsers at the same time, and watch the progress increment from 0% to 100%. But, at some point, the Wcf Services starts blocking. Using Fiddler, I can see the javascript GET requests being sent, but no response comes. The javascript might issue 10 of these before the file upload completes, at which time all 10 responses finally come back, and they all say 100%, which means the code in the Wcf Service was blocked at (or before) trying to access the singleton hashtable.

At first, I was trying to use Session state to store the progress value and retrieve it from the Wcf, but I learned that the Session state for a given SessionId cannot be accessed concurrently by two threads (ie by my action thread and by the Wcf thread), so I switched it to use a static singleton. I've tried both Hashtable and Dictionary<> as the singleton because of their varying thread safety.

What is puzzling is that it works very well for awhile, then hours later when I test, it is exhibiting the blocking behavior again.

This is deployed to a GoDaddy Sindows 4GH Shared Host.


The Wcf Service:
AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class OnoService : IOnoService
. . .
public UploadProgress GetUploadProgress(string controlid)
{
up.PercentComplete = SharedState.GetValue(controlid) as string;
return up;
}


The Containing page: Index.cshtml
<input type="hidden" value="@Session.SessionID" name="controlId" id="controlId"/>
<iframe src="UploadForm">
</iframe>

The IFrame UploadForm
<form action="@Url.Content("~/MemberArea/UploadImage")" method="post" enctype="multipart/form-data">
OwnerId <input type="text" id="ownerId" name="ownerId" />
<input type="hidden" value="@Session.SessionID" name="controlId" id="controlId"/>
Image File <input type="file" id="image" name="image" />
<input type="submit" />
</form>

The Javascript:
$(function () {
monitorProgress();
});

function monitorProgress() {
var controlId = $("#controlId").val();
var url = "Services/OnoService.svc/GetUploadProgress/"+controlId;
$.getJSON(url, function (data) {
var items = [];
var result =data.GetUploadProgressResult.PercentComplete + " %";
$("#progressdiv").text(result);
});
setTimeout("monitorProgress()", 1000);
}

A few excerpts from web.config:
<sessionState mode="InProc" cookieless="UseCookies" regenerateExpiredSessionId="false" />
. . .
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
. . .
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>


So, does anyone have any insight as to why the Wcf Service would be blocking after it has been running for a while?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900