How to configure Parameter/Message length for WCF-RIA-Service operation - web-config

We send bitmaps from our Silverlight client to the server to be saved, using a WCF-RIA defined service operation. Our DomainService class looks a little like this:
[EnableClientAccess()]
public class CBitmapSavingService : DomainService
{
public void SaveBitmap(string bitmapGuid, byte[] pngBytes)
{
// Save PNG on server file system
}
}
Works fine, until we get a large bitmap. Then we get a 'DomainOperationException' exception.
I suspect that we are surpassing a size limit for either the parameter or the message.
Can I reconfigure my service such that larger bitmaps can be sent from the client with WCF-RIA-Services?

I made the following change to my web.config file:
<httpRuntime requestValidationMode="2.0" maxRequestLength="6225920"/>
and it worked.
(why 6225920? Size of 2048*760 bitmap before compression, I gotta choose something)
I found the answer on another site: http://forums.silverlight.net/forums/p/186772/440463.aspx
This is only intended as a short term fix for us, because we don't really want such large bitmaps on the server. I plan to make a client side change, such that the picture type (PNG or JPEG) and quality will be changed to create an image within a defined maximum size.

Related

How do I properly model internal memory in my serial flash device?

I am writing a model for a serial flash device. I wonder how do I best model the internal memory? I would like the memory size to be configurable by the user since I intend to reuse this model for different serial flashes. It also needs to retain its content upon reset while the rest of the logic is reset.
I tried using a statically allocated character buffer but that is not configurable and seems very inappropriate for such large sizes as my flash model. My flash model is 512 MB.
saved char flash_image[512 * 1024 * 1024];
Assuming this will go into Simics, it is best modeled with two subobjects, both of which are available in Simics Base.
The first is an image which stores the actual data, the second is a ram which is used to read/write into the image.
Both the image and the ram are connects using the init_as_subobj template which makes Simics automatically create them as sub-objects of the device.
They are placed in a group where we can add an init method, which sets default values for the required attributes of the subobjects; in this case the "size" of the image and the "image" of the ram.
The ram object also uses the map_target template, which gives us useful methods for reading and writing into the ram.
dml 1.4;
device sample_dev;
import "utility.dml";
import "simics/simulator-api.dml";
group flash is init {
param size = 0x1000;
method init() {
SIM_set_attribute_default(
ram.obj, "image", SIM_make_attr_object(image.obj));
SIM_set_attribute_default(
image.obj, "size", SIM_make_attr_uint64(size));
}
connect image is init_as_subobj {
param classname = "image";
}
connect ram is (init_as_subobj, map_target) {
param classname = "ram";
}
}
method write_test() {
try
flash.ram.write(0, 1, 42);
catch
log error: "write failed, it shouldn't!";
}
The size of the image is given a default value by a parameter in this example, but it can also be set or overridden by the user when creating the object, by assigning to the attribute flash.image.size, e.g. like this:
SIM_create_object("sample_dev", "dev", **{"flash.image.size": 0x2000})

MessageSummaryItems.PreviewText Clarification

We're making use of the newly added MessageSummaryItems.PreviewText feature. Thank you!!
On issue is: sometimes the PreviewText contains HTML links? From reading through the source I see this in ImapFolderFetch.cs
var body = message.TextBody ?? message.HtmlBody;
So this is saying: use the Plaintext version, if it exists, then use the HTML version?
Therefore if I see links in the preview, I can assume no Plaintext version is available?
Our problem with this is:
If our message only has an HTML version, We could strip the links from the message in our code, but there are only 256 characters of it. In many cases, there will be nothing left to display.
As per your TODO: Using the CONVERT extension would be a better approach but, as far as I can tell its not supported by Gmail?
A fall back would be:
If we could set the preview length for both HTML and Plaintext individually, then we could say, If you only have an HTML version give me 1K of it and i'll strip out the links on the client.
Thoughts?
Very few IMAP servers support the CONVERT extension which is the main reason I didn't implement it.
The PreviewText feature is an attempt at adding a convenience feature to fetch the first 256 bytes of each message body in batched requests in order to minimize latency, but no matter what I do, it's not guaranteed to be useful (since there could be a ton of markup before any real text is included in HTML).
If I were to split text and html messages into 2 different batches so that I could request different sizes for each, then it would be less efficient and might take significantly longer to fetch, so I'm not sure if it's really worth it. The less I'm able to batch at a time, the less useful the feature becomes compared to implementing your own loop over the list of messages and downloading your own specified chunk size. one message at a time.
My suggestion would be to use the PreviewText feature and for the rare messages where the 256 bytes isn't enough, perform a folder.GetStream() on them.

No image strip file and no single request with gwts ClientBundle ImageResource

the purpose of gwts clientbundle + imageresource is to reduce the number of http request to one and to minimize the amount of transfered bytes while clientbundle creates a single jpg strip file which contains all my jpg-pics.
As example i have ten pics, clientbundle would put all these ten pics into a single jpg-strip-file
and if the app would call all these images there would be only one http request for the single-jpg-strip file.
thats what i understand.
The thing is that clientbundle is not creating a single strip file.
It creates ten cacheable files but when i am enabling caching it still does not create this single stripfile.
iam understanding something wrong what the purpose of clientbundle is?
There are two small misunderstandings in your question:
ClientBundle will only generate a sprited image for IE6/7; for all other browsers it'll use data: URLs (at least that's the default configuration) until some threshold on the size of the image and then will directly reference the image as an external one (not sprited).
ClientBundle won't generate sprited images (for IE6/7) for images with lossy compression (such as JPEGs), only for those with lossless one (such as PNG or GIF), and only if they're not animated, and only if they're not too big (threshold is controlled by a gwt.imageResource.maxBundleSize system property and defaults to 256 pixels)
In your case, I'd say that the JPEG images cross the threshold so they're not inlined as data: URLs, and because they are JPEG (i.e. with lossy compression) you don't see a sprited image generated either.
Note: there are several threshold actually for the data: URL:
one on the size of the file: https://gwt.googlesource.com/gwt/+/2.5.1/user/src/com/google/gwt/resources/rebind/context/AbstractResourceContext.java
one on the size of the data: URL (after base64-encoding): https://gwt.googlesource.com/gwt/+/2.5.1/user/src/com/google/gwt/resources/rebind/context/InlineResourceContext.java

JPEG encoder super slow, how to Optimize it?

I'm building an App with actionscript 3.0 in my Flash builder. This is a followup question this question.
I need to upload the bytearray to my server, but the function i use to convert the bitmapdata to a ByteArray is super slow, so slow it freezes up my mobile device. My code is as follows:
var jpgenc:JPEGEncoder = new JPEGEncoder(50);
trace('encode');
//encode the bitmapdata object and keep the encoded ByteArray
var imgByteArray:ByteArray = jpgenc.encode(bitmap);
temp2 = File.applicationStorageDirectory.resolvePath("snapshot.jpg");
var fs:FileStream = new FileStream();
trace('fs');
try{
//open file in write mode
fs.open(temp2,FileMode.WRITE);
//write bytes from the byte array
fs.writeBytes(imgByteArray);
//close the file
fs.close();
}catch(e:Error){
Is there a different way to convert it to a byteArray? Is there a better way?
Try to use blooddy library: http://www.blooddy.by . But i didn't test it on mobile devices. Comment if you will have success.
Use BitmapData.encode(), it's faster by orders of magnitude on mobile http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode%28%29
You should try to find a JPEG encoder that is capable of encoding asynchronously. That way the app can still be used while the image is being compressed. I haven't tried any of the libraries, but this one looks promising:
http://segfaultlabs.com/devlogs/alchemy-asynchronous-jpeg-encoding-2
It uses Alchemy, which should make it faster than the JPEGEncoder from as3corelib (which I guess is the one you're using at the moment.)
A native JPEG encoder is ideal, asynchronous would be good, but possibly still slow (just not blocking). Another option:
var pixels:ByteArray = bitmapData.getPixels(bitmapData.rect);
pixels.compress();
I'm not sure of native performance, and performance definitely depends on what kind of images you have.
The answer from Ilya was what did it for me. I downloaded the library and there is an example of how to use it inside. I have been working on getting the CameraUI in flashbuilder to take a picture, encode / compress it, then send it over via a web service to my server (the data was sent as a compressed byte array). I did this:
by.blooddy.crypto.image.JPEGEncoder.encode( bmp, 30 );
Where bmp is my bitmap data. The encode took under 3 seconds and was easily able to fit into my flow of control synchronously. I tried async methods but they ultimately took a really long time and were difficult to track for things like when a user moved from cell service to wifi or from tower to tower while an upload was going on.
Comment here if you need more details.

GWT - How to deliver medical image from server to client where users can do some pixel level processing on image

I am working on a GWT based web app for medical image display and processing. The problem is this kind of medical image do not have the standarded fomat and it is a huge bytearray (size: over 18M). I have to directly read the image byte array and send it to the client for display and further processing. When I transfer a little part of the image (less than 32kb), the client display the pixels normally. But when I transfer the whole image, the console promotes error:
[enter code hereERROR]javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.append(ServerSerializationStreamWriter.java:583)
...
This might be the size limitation of data transfer within GWT, as I've found other‘s solution like:
encode the byte array by using com.google.gwt.user.server.Base64Utils.toBase64(byte[]) . But this method does not work for IE 7. and IE8 has 32kb limit.. IE9 does not have this limit.
Client side:
-ImageService.java
-ImageServiceAsync.java
-WebImage.java (interface)
-ImageArray.java (store the image data from server)
Server side:
-ImageServiceImpl.java
I used a button to active this image data delivery. In the background, ImageServiceImpl read a medical image from disk file and send the data array to client. Now as the limitation that I metioned above, this process will not be succesful if I sent the whole image data. How can I do to complete this process succesfully? I wonder if there is a way to continuously deliver many small parts (<32kb) of data array from server to client when I just click the button once. So I can divide the image into many small parts to perform that. Or there are some other mechanisms useful for this task that I donot know.
I would look at a Map Tiler similar to the way Google maps breaks up images and displays them. Here is a starting place http://www.maptiler.org/ . Here is an example of a company that has done exactly what you are trying to do https://wiki.openmrs.org/display/docs/Google+Maps+Image+Viewer+Module