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 focuses on "how to solve the serialization problem of WCF", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the serialization problem of WCF.
The WCF basic connection has been closed: the connection was closed unexpectedly.
This mistake may happen accidentally. To sum up, there should be two situations that lead to:
1. The transmission data is too large.
In the first case, you can modify the attributes within the nodes generated by the local reference service.
Just increase the value of maxReceivedMessageSize in the binding node. However, it is generally not recommended to use this, for large quantities of data can be solved by paging reading. Because of mass data transmission, it affects the transmission speed and is prone to error.
2. Attribute serialization in transport class
I happen to have encountered this situation. As follows
The server class looks like this, and other properties are omitted.
[DataContract] public class SDataModel {private string id; private DataTypeEnum type; [DataMember] public string ID {get {return id;} set {id = value;}} [DataMember] public DataTypeEnum Type {get {return type;} set {type = value } [DataContract] public enum DataTypeEnum {[EnumMember] type 1 = 1, [EnumMember] type 2 = 2, [EnumMember] type 3 = 3, [EnumMember] type 4 = 4}
At that time, there was a method that needed only a small number of attribute values, which was not needed when Type this property. So
SDataModel model = new SDataModel ()
Model.ID = item.TBP_ID
When transferring the model object to the client, the Type is not included. So the error is reported, and it can't be checked, because the server execution is normal, but the client is abnormal.
The modification is to assign an initial value when the field is defined, and change to
[DataContract] public class SDataModel {private string id; private DataTypeEnum type=DataTypeEnum. Type 1; [DataMember] public string ID {get {return id;} set {id = value;}} [DataMember] public DataTypeEnum Type {get {return type;} set {type = value } [DataContract] public enum DataTypeEnum {[EnumMember] type 1 = 1, [EnumMember] type 2 = 2, [EnumMember] type 3 = 3, [EnumMember] type 4 = 4}
On the other hand, if you use ADO.NET Entity to connect to the database to generate the data model, cancel the delayed loading. In fact, among the problems I encounter, it is mainly the problem of enumerated type transfer. As far as I understand it.
In the process of serialization, the serialization generator parses the basic type of the object into a stream according to the structure of the object, and then transmits it. After receiving, the content in the parsing stream should change the types into strings, match the type names of the local basic types by string matching, and then restore the type of the object, thus restoring the structure and value of the original object.
But for this kind of custom enumeration, if there is no assignment, there is no basic type, so serialization reports an error. Causes the local connection to be closed. As the base type, Int,String and so on, because it is the base type, the corresponding type can be found in serialization, so it will not report an error.
At this point, I believe you have a deeper understanding of "how to solve the serialization problem of WCF". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.