Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Online Members
Shine S
More...
Resources
»
.NET programming
»
WCF/Webservices
Binary data in WCF
Posted Date:
01-Jan-2009
Category:
WCF/Webservices
Author:
Gollapudi Ramya Krishna
Member Level:
Silver
Points
: 4
Binary data in WCF
?? WCF automates mapping bytes to base64Binary in XSD
?? Encoding determines what actually hits the wire
[DataContract(Name="photo")]
public class Photo {
[DataMember(Order=1)]
PhotoMetadata metadata;
[DataMember(Order=2)]
byte[] data;
}
[ServiceContract]
public interface IPhotoShare {
[OperationContract]
Photo GetPhoto(string id);
}
Techniques for handling large data
?? WCF provides techniques/hooks for handling large data
• ?? Transport compression
• ?? Streaming
• ?? Chunking
?? Each requires some work and may affect interoperability
Transport compression
?? Consider transport compression when you're forced to use the
text encoding for interoperability
• ?? Base64 is highly compressible
• ?? IIS 6.0 offers built-in response compression
• ?? Both sides must support it
?? You can write a custom WCF channel to provide compression
Streaming
?? WCF buffers message transmissions by default
• ?? Headers are always buffered
• ?? Body may be buffered or streamed
?? Consider streaming when dealing with large bodies
• ?? Use System.IO.Stream as the input/output type
• ?? It must be the only type in the SOAP body
• ?? Choose a binding that supports streaming
Streaming programming model
[ServiceContract]
Streaming service contract
public interface IPictureServer
{
[OperationContract]
Stream GetPicture(string pictureName);
}
Implementation
internal class PictureServer: IPictureServer {
Stream IPictureServer.GetPicture(string pictureName) {
( gp ){
try {
FileStream reader = new FileStream(pictureName,
FileMode.Open);
return reader;
}
catch (Exception) {
return null;
}
}
}
Streaming configuration
?? Configure a binding that supports streaming
• ?? BasicHttpBinding
• ?? NetTcpBinding
• ?? NetNamedPipeBinding
?? You enabled streaming on the binding via TransferMode
...
transferMode="StreamedResponse"/>
Streaming pros/cons
?? Pros
• ?? Avoids buffering the message body
• ?? Writes directly to transport
?? Cons
• ?? Doesn't work with security or RM (both require buffering)
• ?? Recovering from errors is problematic
• ?? Requires .NET on both sides
Did you like this resource? Share it with your friends and show your love!
Tweet
Responses to "Binary data in WCF"
Author:
ChandraShekar Thota
26 Jan 2009
Member Level:
Gold
Points
: 2
Good one
Chandrashekar Thota(Editor, MVP)
Feedbacks
Post Comment:
Notify me by email when others post comments to this article.
Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
No HTML formatting and links to other web sites are allowed.
This is a strictly moderated site. Absolutely no spam allowed.
Name:
Sign In
to fill automatically.
Email:
(Will not be published, but
required
to validate comment)
Type the numbers and letters shown on the left.
Next Resource:
Hosting WCF and ASP.Net Compatability Mode
Previous Resource:
WCF
Return to Resources
Post New Resource
Category:
WCF/Webservices
Post resources and
earn money
!
More Resources
Hosting WCF and ASP.Net Compatability Mode
Bindings
WEB Service Part 1
Web Services and their benefits
WCF Fundamentals:
Asynchronous Web Service in .NET
Popular Tags
Tag posting guidelines
Search Tags
Binary data in WCF
.
Active Members
Today
Prachi Kulkarn...
(37)
Hemanth
(25)
Prasad kulkarn...
(25)
Last 7 Days
Naved Hasan ...
(255)
naveensanagase...
(230)
Pawan Awasthi
(176)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds
Talk to Webmaster Tony John