In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use WCF Stream objects". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
WCF supports operations on Stream objects, especially for messages whose size is too large. If you want to consider the efficiency of message delivery, WCF recommends operating through Stream.
However, there are some restrictions on WCF Stream object manipulation, and when we write related programs, we need to pay special attention to:
1. Restrictions on binding
If you need to use Stream operations, the only bindings you can use are BasicHttpBinding,NetTcpBinding and NetNamedPipeBinding. In addition, ReliableMessaging cannot be used when using Stream operations. This approach is not advisable if message security is taken into account.
2. Restrictions on WCF Stream objects
To be a message object passed by a service operation, such an object must be serializable. Unfortunately, the definition of the FileStream class does not support serialization, and we can use WCF Stream objects, including Stream,MemoryStream, and so on. Using Stream class objects is the * of most Stream operations. An interesting phenomenon is the conversion between FileStream and Stream types. For example, in the operation of a service contract, there is the following implementation:
PublicStreamTransferDocument (Documentdocument) {FileStreamstream=newFileStream (document.LocalPath,FileMode.Open,FileAccess.Read); returnstream;}
Note that the return type of the operation TransferDocument () is Stream, while in the implementation of the method, the returned object is of type FileStream. Because the Stream class is the parent of the FileStream class, there is no problem with such an implementation.
However, when the client invokes the operation, you cannot assign the return value of the operation to an object of type FileStream, as follows:
Streamstream=m_service.TransferDocument (doc)
The Stream object obtained at this point is null. Therefore, we can only invoke the operation like this:
Streamstream=m_service.TransferDocument (doc)
However, another strange problem is that WCF does not support the serialization of the Length property of the Stream object, that is, we cannot use the Length property of the Stream object returned by the service operation on the client side. Calls such as stream.Length throw a NotSupportedException exception.
3. Restrictions on TransferMode
To use the Stream operation, you must modify the TransferMode property of the binding. The default value for this property is Buffered. We should determine whether the value of TransferMode is Streamed, StreamedRequest, or StreamedResponse, respectively, based on the parameter type of the Stream object in the operation.
That's all for "how to use WCF Stream objects". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.