2

I would like to know, if there is any possibility to return anything, when I send data though WCF using streaming? I use netTcpBinding, client and server are in the same local network.

Here is my code:

[ServiceContract()]
public interface IFileTransferService
{
    [OperationContract(IsOneWay = true)]
    //[FaultContract(typeof(MyFaultException))] // I can't do that
    void Upload(FileTransferRequest request);
}

[MessageContract()]
public class FileTransferRequest
{
    [MessageHeader(MustUnderstand = true)]
    public string FileName;

    [MessageBodyMember(Order = 1)]
    public System.IO.Stream Data;

}

[DataContract]
public class MyFaultException
{
    private string _reason;
    [DataMember]
    public string Reason
    {
        get { return _reason; }
        set { _reason = value; }
    }
}

So, when using Message Contract, the transaction must be one way, I can't return any value, I can't throw exception. How Can I inform client, that operation was successful or not? And send him an error messages for example?

Marshall
  • 1,195
  • 6
  • 30
  • 47
  • 2
    It's got to be one-way because you decorated your `OperationContract` as one-way. Has nothing to do with your `MessageContract`. – GalacticCowboy Jul 23 '11 at 15:28

1 Answers1

4

So, when using Message Contract, the transaction must be one way, I can't return any value, I can't throw exception.

Where did you find such information? You can of course return a value - you can either return void or another message contract. Also what you mean by "transaction"?

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • 2
    I think that's the most important point - if you use a MessageContract in the request, your response object has to be a MessageContract too. – GalacticCowboy Jul 23 '11 at 15:30
  • I can't return "int" for example. I can return "void. int Upload(FileTransferRequest request); - will fail. I mean "operation", not transaction. sorry – Marshall Jul 23 '11 at 16:24
  • 2
    Simply create `MessageContract` which will have singly `MessageBodyMember` of type int and it will work but as mentioned by @GalacticCowboy you can't have your operation one-way. – Ladislav Mrnka Jul 23 '11 at 16:36
  • If you want to return anything back you can't have it one-way. One-way says: This method will never returns anything so client doesn't have to wait for it. – Ladislav Mrnka Jul 23 '11 at 16:58
  • Yes, I understand.. But return MessageContract work just fine! Thank you. So, when Message Contract is somehow involved in operation contract, you can return only message contract or "void". – Marshall Jul 23 '11 at 17:16
  • 1
    Yes. Involving message contract changes the message processing so you must use message contract for both request and response or return void. – Ladislav Mrnka Jul 23 '11 at 17:24
  • So in your specific scenario, you'll need to have a `MessageContract` return object, and that object needs to include some way to report an error, if one occurred. – GalacticCowboy Jul 23 '11 at 18:23
  • Error can be reported by `FaultContract` but the operation mustn't be one way. – Ladislav Mrnka Jul 23 '11 at 18:32