Some classes do not work correctly after the WinForm client references a WCF client

Source: Internet
Author: User

Using WCF in your project, the structure of the project is this:


write the common classes and functions in this solution in the SPI project;
The Svc file and the WCF service interface are written in the Wcfservice project;
When you add a WCF service reference in the client, the Wcfservice project then initializes the instance of the client in the UI project. Pass the method in the instance Wcfservice.
Problem:

Sometimes there is a situation in the UI by initializing an instance of the client. Through the method MethodA in the example Wcfservice, the entry parameter of the method is an instance of class ConnectionInfo in the SPI. Then when you use class ConnectionInfo again in the UI, you will find that ConnectionInfo is a class under the client namespace, not a class under the SPI namespace.

In the WCF auto-generated client proxy class (Reference.cs file ) , the class ConnectionInfo in the SPI is serialized into :

 [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.serializableattribu TE ()] public partial class Connectioninfo:object, System.Runtime.Serialization.IExtensibleDataObject, System.compone ntmodel.inotifypropertychanged {[System.nonserializedattribute ()] Private System.Runtime.Serializat Ion.                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.extensiondata            Field;            } 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.m            Enuguidfield; } 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.PropertyChangedEv Enthandler propertychanged = this.            propertychanged; if (propertychanged! = null)) {propertychanged (this, new System.ComponentModel.PropertyChangedEventArgs (p            Ropertyname)); }        }    }
the entity 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;}    }

You can see the entity class by right-clicking on the WCF reference of the client project


The DLL can be found in the project


Open the DLL and you can see the information for that class


The class information you see here is the class information that is transferred to the WCF Data contract form


Solution:

If you want to use class ConnectionInfo under the SPI namespace in your UI project, delete the public partial class ConnectionInfo in the Reference.cs file. You can then reference the SPI project in the UI.

Small bet

This problem can also be solved by using WebService.
However, the cause of this problem is not yet found because the SPI project is already referenced in the UI project, and information about the ConnectionInfo class is generated in the Reference.cs file. The friend who wants to know the reason is left to say, thank you.

Copyright: jiankunking Source: http://blog.csdn.net/jiankunking This article is copyright to the author and Csdn, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original connection.

Some classes do not work correctly after the WinForm client references a WCF client

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.