none
How do I call client operation for streaming service with MessageContract, that gets and returns a large stream RRS feed

  • Question

  • I have a requirement for a WCF service operation that accepts a large Stream, processes it and returns that stream.

    I used an MSDN article on Large data Streaming as a reference to what I need (unfortunately, I am not allowed to post links).

    Following the advice in that article:

    Details:

    Because I need to accompany both the input and return streams with MetaData, I decorated the classes with MessageContract attributes, as is required.

    Here is a brief run-down of my implementation:

    Message Contracts:

    [MessageContract]
    public class InputStreamMessage
    {
        [MessageHeader]
        public InputStreamHeader Header { get; set; }
    
        [MessageBodyMember(Order = 1)]
        public Stream Data { get; set; }
    
    }
    
    [MessageContract]
    public class OutputStreamMessage
    {
        [MessageHeader]
        public OutputStreamHeader Header { get; set; }
    
        [MessageBodyMember(Order = 1)]
        public Stream Data { get; set; }
    
    }

    Service Contract:

    [ServiceContract]
    public interface IStreamService
    {
        [OperationContract]
        OutputStreamMessage ProcessStream(InputStreamMessage input);
    }

    Service Implementation:

     public OutputStreamMessage DoStreamOperation(InputStreamMessage input)
     {
        //Some logic that assigns re
        OutputStreamMessage output = DoSomeNonBufferedProcessing(input);
    
        return output;
     }

    Client-side:

    On the client-side, I then generate the service reference, and call the service as below:

    private void PerformStreamOperation()
    {
        try
        {
            //
            StreamServiceReference.StreamServiceClient client = new StreamServiceReference.StreamServiceReferenceClient();
            client.Open();
    
            //Set Header and Parameters
            InputMessageHeader header = new InputMessageHeader();
    
            //...                
            //... initialize header data here
            //...                
    
            //... do some operation to get input stream
            var inputstream = SomeOperationToGetInputStream();
    
            //Perform Service stream action
            //         ____ [ Why does the generated method have the following signature, retuning void?]
            //        |     [ If this is expected, how do I use it? ]
            //        |
            //        V 
            client.DoStreamOperation(header, ref inputstream); 
    
    
            //...                
            //... Do what you wish with data
            //...                
    
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString(), "Stream Processing Error");
        }
    }
    The MSDN article uses the exact same contract that exists in the official WCF samples(not allowed to post links).

    But no example of an equivalent MessageContract implementation. The sample version does an expected return.

    Questions:

    1. I would like to know why the generated service operation does not have a return type when I specified it in the contract?

    2. If that is expected behaviour, how should I get it to pass on a stream and return a processed stream?





    Wednesday, March 4, 2015 2:09 AM

Answers

  • Hi kenchanX,

    >>I would like to know why the generated service operation does not have a return type when I specified it in the contract?

    Based on your description, I know that when you use the client.DoStreamOperation method, it will return the void type but not the OutputStreamMessage type. Then I have done a simple test about your code, it works very well in my side with the expected return type(OutputStreamMessage type).

    So in my mind, maybe you forget to click the "Always generate message contracts" when adding the services reference. Please try to make sure that you have done the following:

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, March 17, 2015 10:11 AM
    Moderator

All replies

  • Bump
    Friday, March 6, 2015 12:34 PM
  • Hi kenchanX,

    In order to create the streaming service with the MessageContract, please first try to make sure that you do not use the wsHttpBinding. Because the wsHttpBinding does not support streaming, the whole message is buffered on the server, transfered to the client and buffered on the client. So please try to use basicHttpBinding or netTcpBinding instead. After that please try to refer to the following article about how to implement a streaming service with the MessageContract:
    http://blog.monogram.sk/pokojny/2011/09/22/wcf-streaming/ .

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 9, 2015 6:29 AM
    Moderator
  • Hi Amy,

    Thanks for the response

    I am already using NetTcpBinding.

    The link you posted has an example with just an input stream.

    I would like an example of an input and output in the same method. Meaning, it should stream in then process and then return the processed stream, continuously...

    E.g.

    MessageContractClass Echo(MessageContractClass input);

    The Official WCF samples have a method that looks as follows:

    Stream Echo(Stream data);
    There is no working example showing a MessageContract implementation, which is failing on my side


    • Edited by kenchanX Wednesday, March 11, 2015 3:35 AM
    Tuesday, March 10, 2015 2:15 PM
  • Hi kenchanX,

    >>I would like to know why the generated service operation does not have a return type when I specified it in the contract?

    Based on your description, I know that when you use the client.DoStreamOperation method, it will return the void type but not the OutputStreamMessage type. Then I have done a simple test about your code, it works very well in my side with the expected return type(OutputStreamMessage type).

    So in my mind, maybe you forget to click the "Always generate message contracts" when adding the services reference. Please try to make sure that you have done the following:

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, March 17, 2015 10:11 AM
    Moderator