by Keyvan Nayyeri via Keyvan Nayyeri on 6/24/2007 3:57:16 PM
By default WCF uses a buffered mechanism to send or receive messages to or from services. It means that messages can't be accessed before they arrive to service or client completely. But it's possible to choose streaming mechanism to send or receive messages. This way, messages will be streamed and can be accessed before they arrive completely to service or client. You can use streaming for requests only, responses only or both.
Implementing this mechanism is very easy. As an obvious step, you must return your stream content from service methods. For example, suppose that I have a very simple service contract like this:
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.IO;
namespace StreamingInWCF
{
[ServiceContract()]
public interface IMyService
[OperationContract]
Stream GetStream(string path);
}
And my service implementation gets a file path and returns its streamed content as result.
public class MyService : IMyService
#region IMyService Members
public Stream GetStream(string path)
return new MemoryStream(File.ReadAllBytes(path));
#endregion
Now I can use streamed transfers for my service. There are four types of transfer modes available in WCF: Buffered (default), Streamed, StreamedRequest and StreamedResponse. You can set this mode via transferMode attribute for your binding in your service configuration file. Note that not all binding types support streamed transfers so your binding must support streamed transfers to be able to use it. Regarding this point, my service configuration file looks like this:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="StreamingInWCF.MyService"
behaviorConfiguration="metadataSupport">
<endpoint contract="StreamingInWCF.IMyService"
binding="basicHttpBinding" bindingName="MyBinding"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="MyBinding" transferMode="Streamed" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
After this I can use streamed transfers in my WCF application to let my services or clients to begin processing on messages sooner than when they get to them.
Now playing: Ennio Morricone - The Good, The Bad And The Ugly
Original Post: Streaming Content in Windows Communication Foundation
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.