Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a requirement for a WCF service operation that accepts a large Stream, processes it and returns that stream.

I used an https://msdn.microsoft.com/en-us/library/ms733742.aspx[^] 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:

C#
[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:

C#
[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:

C#
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 almost the same contract format(without meta data) that exists in the official WCF samples[^]- Look at

C#
[OperationContract]
Stream EchoStream(Stream stream)


But no example of an equivalent MessageContract implementation. The generated service reference method accepts a stream and returns a stream.

Questions:


  • I would like to know why the generated service operation does not have a return type when I specified it in the contract?
  • If that is expected behaviour, how should I get it to pass on a stream and return a processed stream?
  • If I designed my logic wrongly, what would be the recommended way?
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