WCF generated client code

Posts   
 
    
El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 05-Feb-2013 14:43:12   

I've build a wcf service which accepts generated entity types. This service has been working well. Last month I've upgraded to VS2012 and LLBLGen 3.5 (dec 11th). Today I found out when I update the client, the generated client code has compile errors.

The WCF interface code:


    [ServiceKnownType("GetKnownTypes", typeof(SapEntityHelper))]
    public interface ISapUpdateService {
        [OperationContract]
        bool HandleAndRun(string databaseName, IEntity2 entity);

    }

    static class SapEntityHelper {
        public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider) {
            List<Type> knownTypes = new List<Type>(typeof(CommonEntityBase).Assembly.GetTypes().Where(t => (t.Name.StartsWith("Sap") || t.Name.StartsWith("Svh")) && t.Name.EndsWith("Entity")));
            return knownTypes;
        }
    }


In the generated reference.cs file I can see the knowntypes:


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="xxxxxxx", ConfigurationName="SapUpdateService.ISapUpdateService")]
    public interface ISapUpdateService {
        
        // CODEGEN: Parameter 'databaseName' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
        [System.ServiceModel.OperationContractAttribute(Action="xxxxxxx", ReplyAction="xxxxxxxx")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhWebcatEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhWebalternativeEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhTeleritemEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhLekkerbijEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhItemwebcatEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhItemstatrEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhItemstatEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhDisctypeEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhDisccouprelEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhDisccouponEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapUpdateEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapSpp2Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapSpp1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapRdr1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOvtgEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOshpEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOrpdEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOrdrEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOpymEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOporEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOitwEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOctgEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOcrdEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOcprEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapItt1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapItm1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapInv3Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapInv1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapCrd2Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapCrd1Entity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOitmEntity))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SapOinvEntity))]
        RSS.VH.Web.SapUpdateService.HandleAndRunResponse HandleAndRun(RSS.VH.Web.SapUpdateService.HandleAndRunRequest request);


This is the same for the working "old" generated client and for the new generated client. The problem in the newly generated client is, each knowntype is extended as partial class and has an extra property of type schema. The compiler does not know this type. The old generated client does not have a partial class for each knowntype.


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.datacontract.org/2004/07/RSS.VH.EntityClasses")]
    public partial class SvhWebcatEntity : object, System.ComponentModel.INotifyPropertyChanged {
        
        private schema schemaField;
        
        private System.Xml.XmlElement anyField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.w3.org/2001/XMLSchema", Order=0)]
        public schema schema {
            get {
                return this.schemaField;
            }
            set {
                this.schemaField = value;
                this.RaisePropertyChanged("schema");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAnyElementAttribute(Order=1)]
        public System.Xml.XmlElement Any {
            get {
                return this.anyField;
            }
            set {
                this.anyField = value;
                this.RaisePropertyChanged("Any");
            }
        }
        
        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));
            }
        }
    }

I guess this a new feature of VS2012, so I might be in the wrong place to ask this question here, but has anyone stumble upon this problem and might have a solution for this?

El Barto
User
Posts: 64
Joined: 09-Nov-2006
# Posted on: 05-Feb-2013 15:38:06   

I finally found the solution. I noticed a difference in the generated code of the old and the new client.

The old client was:


[System.ServiceModel.ServiceKnownTypeAttribute(typeof(RSS.VH.EntityClasses.SvhWebcatEntity))]

The new client was:


[System.ServiceModel.ServiceKnownTypeAttribute(typeof(SvhWebcatEntity))]

So it seemed the generator wasn't able to reuse the types and created its own ones. Then I remembered I had more problems with existing references in other projects after they where converted to VS2012. So I deleted and readded the references which solved the problem.