After the Winform client references the WCF client, the local category cannot be used normally.

Source: Internet
Author: User

After the Winform client references the WCF client, the local category cannot be used normally.

The project structure is as follows:


Write common classes and functions in the solution in the SPI project;
The svc file and the WCF Service Interface are written in the WCFService project;
Add the WCFService project when the WCF Service reference is added to the Client, and then initialize the Client instance in the UI project. Use the method in the WCFService instance.
Problem:

Sometimes, the Client instance is initialized in the UI. Using the method MethodA in WCFService of this instance, the input parameter of this method is an instance of ConnectionInfo class in SPI, when you use ConnectionInfo again in the UI, you will find that ConnectionInfo is a class in the Client namespace, rather than a class in the SPI namespace.

In the client proxy class (Reference. cs file) automatically generated by WCF, The ConnectionInfo class in SPI is serialized:

 [System.Diagnostics.DebuggerStepThroughAttribute()]    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]    [System.Runtime.Serialization.DataContractAttribute(Name="ConnectionInfo", Namespace="http://schemas.datacontract.org/2004/07/HaiChuang.AMAC.DataSourceSettings.SPI.Mod" +        "el")]    [System.SerializableAttribute()]    public partial class ConnectionInfo : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {                [System.NonSerializedAttribute()]        private System.Runtime.Serialization.ExtensionDataObject extensionDataField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string ConnectionStringField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string GuidField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string LocationField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string MenuGuidField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string NameField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private string TypeField;                [System.Runtime.Serialization.OptionalFieldAttribute()]        private int idField;                [global::System.ComponentModel.BrowsableAttribute(false)]        public System.Runtime.Serialization.ExtensionDataObject ExtensionData {            get {                return this.extensionDataField;            }            set {                this.extensionDataField = value;            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string ConnectionString {            get {                return this.ConnectionStringField;            }            set {                if ((object.ReferenceEquals(this.ConnectionStringField, value) != true)) {                    this.ConnectionStringField = value;                    this.RaisePropertyChanged("ConnectionString");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string Guid {            get {                return this.GuidField;            }            set {                if ((object.ReferenceEquals(this.GuidField, value) != true)) {                    this.GuidField = value;                    this.RaisePropertyChanged("Guid");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string Location {            get {                return this.LocationField;            }            set {                if ((object.ReferenceEquals(this.LocationField, value) != true)) {                    this.LocationField = value;                    this.RaisePropertyChanged("Location");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string MenuGuid {            get {                return this.MenuGuidField;            }            set {                if ((object.ReferenceEquals(this.MenuGuidField, value) != true)) {                    this.MenuGuidField = value;                    this.RaisePropertyChanged("MenuGuid");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string Name {            get {                return this.NameField;            }            set {                if ((object.ReferenceEquals(this.NameField, value) != true)) {                    this.NameField = value;                    this.RaisePropertyChanged("Name");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public string Type {            get {                return this.TypeField;            }            set {                if ((object.ReferenceEquals(this.TypeField, value) != true)) {                    this.TypeField = value;                    this.RaisePropertyChanged("Type");                }            }        }                [System.Runtime.Serialization.DataMemberAttribute()]        public int id {            get {                return this.idField;            }            set {                if ((this.idField.Equals(value) != true)) {                    this.idField = value;                    this.RaisePropertyChanged("id");                }            }        }                public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;                protected void RaisePropertyChanged(string propertyName) {            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;            if ((propertyChanged != null)) {                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));            }        }    }
The object class code is:

/// <Summary> // data source information // </summary> public class ConnectionInfo {public int id {get; set;} public string Guid {get; set ;} public string Name {get; set;} public string Location {get; set;} public string Type {get; set;} public string ConnectionString {get; set ;} public string MenuGuid {get; set ;}}

Right-click the CLient project's wcf reference and you can see the object class


You can find the dll in the project


Open the dll to view the information of this class.


The class information shown here is converted to the class information in the form of a WCF data contract.


Solution:

  If you want to use the class ConnectionInfo In the SPI namespace in the UI project, delete the public partial class ConnectionInfo in the Reference. cs file, and then Reference the SPI project in the UI.

Note:

This problem also occurs when using WebService. The solution is the same.
The cause of this problem is not found yet. Because the SPI project has been referenced in the UI project, the ConnectionInfo class information will still be generated in the Reference. cs file. If you want to know the reason, leave a message. Thank you.

Copyright Disclaimer: Author: jiankunking Source: http://blog.csdn.net/jiankunking this article copyright to the author and CSDN a total, welcome to reprint, but without the author's consent must retain this statement, and in the Article Page clearly given the original connection.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.