Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Asheej T K
(144)
Manindra Upadh...
(76)
Avinash Mohan
(44)
Last 7 Days
Alwyn
(922)
Asheej T K
(717)
Manindra Upadh...
(542)
more...
Resources
»
Articles
»
WCF/Webservices
»
Binary data in WCF
Posted Date: 01 Jan 2009
Resource Type:
Articles
Category:
WCF/Webservices
Author:
Gollapudi Ramya Krishna
Member Level:
Gold
Rating:
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
Responses
Author:
ChandraShekar Thota
26 Jan 2009
Member Level:
Diamond
Points
: 2
Good one
Chandrashekar Thota(Editor, MVP)
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
Binary data in WCF
.
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Hosting WCF and ASP.Net Compatability Mode
Previous Resource:
WCF
Return to Discussion Resource Index
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
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use