views:

101

answers:

2

My WCF service contract has to methods like these:

    [OperationContract]
    string GetFile(int id);

    [OperationContract]
    void UploadFile(int id, string text);

GetFile returns a text of a file and UploadFile sends some file's content to a server.

There is a strange behavior, when file's size is about few MB (4.37 MB in my case): GetFile works fine and client gets long text without any problem, but UploadFile cannot send the same file to a server. Client freezes while executing this method and it seems not to be going to finish the operation. I was waiting for some minutes, but there were no result and I stopped client forcibly.

So, my question is is there any difference between directions of such transferring? I know about WCF streaming, which should be used for sending large files to server, and I'm going to to change my code using it. I wonder why the problem occures only when a file is transferred to a server while a server returns data of the same size correctly?

Update. UploadFile shouldn't be a OneWay operation, because I need to know if it has been successful. Execution doesn't rich the server. I set breakpoint on the server side and it doesn't fire.

+1  A: 

I guess you have already configured maxReceivedMessageSize and reader quotas on both server and client. Otherwise you should not be able to send such big messages. Do you host your WCF service in IIS? Http runtime has its own limit which is 4MB. It can be changed in configuration/system.web/httpRuntime/@maxRequestLength (value is in KB). I wonder why you don't receive any exception.

Ladislav Mrnka
exactly what I was going to suggest!
BerggreenDK
A: 

Is it possible that the client's simply waiting for the UploadFile to return?

One thing you could do is to fire the UploadFile method call on a separate through so you don't block the UI thread (assuming the client you're talking about is a GUI app).

It might be worth setting the OperationContract of UploadFile to [OperationContract(IsOneWay = true)] so that the client doesn't wait for the server to respond. Even if the return type of UploadFile is void the server will still respond with an empty message unless IsOneWay is set to true. As Ladislav mentioned though, doing so gives you a fire-and-forget behaviour and you won't find out if the server excepts whilst processing your call.

theburningmonk
But if you set IsOneWay=true you will never know if upload was successful.
Ladislav Mrnka
@Ladislav - that's true, but often you don't really care and just want to fire and forget, from the question I can't really tell hence the suggestion. Should've mentioned it though I guess, updated my answer
theburningmonk