示例#1
0
        public ContractDescription(string name, string ns)
        {
            // the property setter validates given value
            this.Name = name;
            if (!string.IsNullOrEmpty(ns))
            {
                NamingHelper.CheckUriParameter(ns, "ns");
            }

            _operations = new OperationDescriptionCollection();
            _ns         = ns ?? NamingHelper.DefaultNamespace; // ns can be ""
        }
 public MessagePartDescription(string name, string ns)
 {
     if (name == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name", System.ServiceModel.SR.GetString("SFxParameterNameCannotBeNull"));
     }
     this.name = new System.ServiceModel.Description.XmlName(name, true);
     if (!string.IsNullOrEmpty(ns))
     {
         NamingHelper.CheckUriParameter(ns, "ns");
     }
     this.ns = ns;
 }
        private static CodeTypeDeclaration CreateOperationCompletedEventArgsType(ServiceContractGenerationContext context, string syncMethodName, CodeMemberMethod endMethod)
        {
            if ((endMethod.Parameters.Count == 1) && (endMethod.ReturnType.BaseType == voidTypeRef.BaseType))
            {
                return(null);
            }
            CodeTypeDeclaration ownerTypeDecl = context.TypeFactory.CreateClassType();

            ownerTypeDecl.BaseTypes.Add(new CodeTypeReference(asyncCompletedEventArgsType));
            CodeMemberField field = new CodeMemberField {
                Type = new CodeTypeReference(objectArrayType)
            };
            CodeFieldReferenceExpression left = new CodeFieldReferenceExpression {
                TargetObject = new CodeThisReferenceExpression()
            };
            CodeConstructor constructor = new CodeConstructor {
                Attributes = MemberAttributes.Public
            };

            for (int i = 0; i < EventArgsCtorParamTypes.Length; i++)
            {
                constructor.Parameters.Add(new CodeParameterDeclarationExpression(EventArgsCtorParamTypes[i], EventArgsCtorParamNames[i]));
                if (i > 0)
                {
                    constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(EventArgsCtorParamNames[i]));
                }
            }
            ownerTypeDecl.Members.Add(constructor);
            constructor.Statements.Add(new CodeAssignStatement(left, new CodeVariableReferenceExpression(EventArgsCtorParamNames[0])));
            int asyncResultParamIndex = GetAsyncResultParamIndex(endMethod);
            int num3 = 0;

            for (int j = 0; j < endMethod.Parameters.Count; j++)
            {
                if (j != asyncResultParamIndex)
                {
                    CreateEventAsyncCompletedArgsTypeProperty(ownerTypeDecl, endMethod.Parameters[j].Type, endMethod.Parameters[j].Name, new CodeArrayIndexerExpression(left, new CodeExpression[] { new CodePrimitiveExpression(num3++) }));
                }
            }
            if (endMethod.ReturnType.BaseType != voidTypeRef.BaseType)
            {
                CreateEventAsyncCompletedArgsTypeProperty(ownerTypeDecl, endMethod.ReturnType, NamingHelper.GetUniqueName("Result", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMemberNameExist), ownerTypeDecl), new CodeArrayIndexerExpression(left, new CodeExpression[] { new CodePrimitiveExpression(num3) }));
            }
            field.Name     = NamingHelper.GetUniqueName("results", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMemberNameExist), ownerTypeDecl);
            left.FieldName = field.Name;
            ownerTypeDecl.Members.Add(field);
            ownerTypeDecl.Name = NamingHelper.GetUniqueName(GetOperationCompletedEventArgsTypeName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesTypeAndMemberNameExist), new object[] { context.Namespace.Types, ownerTypeDecl });
            context.Namespace.Types.Add(ownerTypeDecl);
            return(ownerTypeDecl);
        }
        internal ChannelEndpointElement WriteChannelDescription(ServiceEndpoint endpoint, string typeName)
        {
            ChannelEndpointElement element = null;
            BindingDictionaryValue value2  = this.CreateBindingConfig(endpoint.Binding);

            element = new ChannelEndpointElement(endpoint.Address, typeName)
            {
                Name = NamingHelper.GetUniqueName(NamingHelper.CodeName(endpoint.Name), new NamingHelper.DoesNameExist(this.CheckIfChannelNameInUse), null),
                BindingConfiguration = value2.BindingName,
                Binding = value2.BindingSectionName
            };
            this.channels.Add(element);
            return(element);
        }
示例#5
0
        private static OperationFormatter GetOperationFormatter(System.Type t, Attribute formatAttribute, string defaultNS, string action)
        {
            bool flag = formatAttribute is XmlSerializerFormatAttribute;
            MessageDescription   description       = new TypeLoader().CreateTypedMessageDescription(t, null, null, defaultNS, action, MessageDirection.Output);
            ContractDescription  declaringContract = new ContractDescription("dummy_contract", defaultNS);
            OperationDescription operation         = new OperationDescription(NamingHelper.XmlName(t.Name), declaringContract, false)
            {
                Messages = { description }
            };

            if (flag)
            {
                return(XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)formatAttribute));
            }
            return(new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttribute, null));
        }
示例#6
0
        public MessagePartDescription(string name, string ns)
        {
            if (name == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("name", SR.SFxParameterNameCannotBeNull);
            }

            _name = new XmlName(name, true /*isEncoded*/);

            if (!string.IsNullOrEmpty(ns))
            {
                NamingHelper.CheckUriParameter(ns, "ns");
            }

            _ns = ns;
        }
        private BindingDictionaryValue CreateBindingConfig(Binding binding)
        {
            BindingDictionaryValue value2;

            if (!this.bindingTable.TryGetValue(binding, out value2))
            {
                string str2;
                string name = NamingHelper.GetUniqueName(NamingHelper.CodeName(binding.Name), new NamingHelper.DoesNameExist(this.CheckIfBindingNameInUse), null);
                if (!BindingsSection.TryAdd(name, binding, this.config, out str2))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("ConfigBindingCannotBeConfigured"), "endpoint.Binding"));
                }
                value2 = new BindingDictionaryValue(name, str2);
                this.bindingTable.Add(binding, value2);
            }
            return(value2);
        }
        private static CodeMemberEvent CreateOperationCompletedEvent(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeTypeDeclaration operationCompletedEventArgsType)
        {
            CodeMemberEvent event2 = new CodeMemberEvent {
                Attributes = MemberAttributes.Public,
                Type       = new CodeTypeReference(eventHandlerType)
            };

            if (operationCompletedEventArgsType == null)
            {
                event2.Type.TypeArguments.Add(asyncCompletedEventArgsType);
            }
            else
            {
                event2.Type.TypeArguments.Add(operationCompletedEventArgsType.Name);
            }
            event2.Name = NamingHelper.GetUniqueName(GetOperationCompletedEventName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
            clientType.Members.Add(event2);
            return(event2);
        }
        private static CodeMemberMethod CreateEventAsyncMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod, CodeMemberField beginOperationDelegate, CodeMemberMethod beginOperationMethod, CodeMemberField endOperationDelegate, CodeMemberMethod endOperationMethod, CodeMemberField operationCompletedDelegate, CodeMemberMethod operationCompletedMethod)
        {
            CodeMemberMethod nameCollection = new CodeMemberMethod {
                Name       = NamingHelper.GetUniqueName(GetEventAsyncMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations),
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                ReturnType = new CodeTypeReference(voidType)
            };
            CodeArrayCreateExpression expression = new CodeArrayCreateExpression(new CodeTypeReference(objectArrayType), new CodeExpression[0]);

            for (int i = 0; i < (beginMethod.Parameters.Count - 2); i++)
            {
                CodeParameterDeclarationExpression expression2 = beginMethod.Parameters[i];
                CodeParameterDeclarationExpression expression3 = new CodeParameterDeclarationExpression(expression2.Type, expression2.Name)
                {
                    Direction = FieldDirection.In
                };
                nameCollection.Parameters.Add(expression3);
                expression.Initializers.Add(new CodeVariableReferenceExpression(expression3.Name));
            }
            string name = NamingHelper.GetUniqueName("userState", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), nameCollection);

            nameCollection.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(objectType), name));
            nameCollection.Statements.Add(CreateDelegateIfNotNull(beginOperationDelegate, beginOperationMethod));
            nameCollection.Statements.Add(CreateDelegateIfNotNull(endOperationDelegate, endOperationMethod));
            nameCollection.Statements.Add(CreateDelegateIfNotNull(operationCompletedDelegate, operationCompletedMethod));
            CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression(new CodeBaseReferenceExpression(), invokeAsyncMethodName, new CodeExpression[0]);

            expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), beginOperationDelegate.Name));
            if (expression.Initializers.Count > 0)
            {
                expression4.Parameters.Add(expression);
            }
            else
            {
                expression4.Parameters.Add(new CodePrimitiveExpression(null));
            }
            expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), endOperationDelegate.Name));
            expression4.Parameters.Add(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), operationCompletedDelegate.Name));
            expression4.Parameters.Add(new CodeVariableReferenceExpression(name));
            nameCollection.Statements.Add(new CodeExpressionStatement(expression4));
            clientType.Members.Add(nameCollection);
            return(nameCollection);
        }
 private void ExportMembersMapping(XmlMembersMapping membersMapping, Message message, bool skipSchemaExport, bool isEncoded, bool isRpc, bool isDocWrapped, bool isHeader)
 {
     if (!skipSchemaExport)
     {
         if (isEncoded)
         {
             this.SoapExporter.ExportMembersMapping(membersMapping);
         }
         else
         {
             this.XmlExporter.ExportMembersMapping(membersMapping, !isRpc);
         }
     }
     if (isDocWrapped)
     {
         if (isHeader)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Header cannot be Document Wrapped", new object[0])));
         }
         MessageContractExporter.AddMessagePart(message, "parameters", new XmlQualifiedName(membersMapping.XsdElementName, membersMapping.Namespace), XmlQualifiedName.Empty);
     }
     else
     {
         bool flag = !isRpc && !isEncoded;
         for (int i = 0; i < membersMapping.Count; i++)
         {
             XmlMemberMapping mapping  = membersMapping[i];
             string           partName = (isHeader || flag) ? NamingHelper.XmlName(mapping.MemberName) : mapping.XsdElementName;
             if (flag)
             {
                 MessageContractExporter.AddMessagePart(message, partName, new XmlQualifiedName(mapping.XsdElementName, mapping.Namespace), XmlQualifiedName.Empty);
             }
             else
             {
                 if (string.IsNullOrEmpty(mapping.TypeName))
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxAnonymousTypeNotSupported", new object[] { message.Name, partName })));
                 }
                 MessageContractExporter.AddMessagePart(message, partName, XmlQualifiedName.Empty, new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace));
             }
         }
     }
 }
        static OperationFormatter GetOperationFormatter(Type t, Attribute formatAttribute, string defaultNS, string action)
        {
            bool                 isXmlSerializer = (formatAttribute is XmlSerializerFormatAttribute);
            TypeLoader           typeLoader      = new TypeLoader();
            MessageDescription   message         = typeLoader.CreateTypedMessageDescription(t, null, null, defaultNS, action, MessageDirection.Output);
            ContractDescription  contract        = new ContractDescription("dummy_contract", defaultNS);
            OperationDescription operation       = new OperationDescription(NamingHelper.XmlName(t.Name), contract, false);

            operation.Messages.Add(message);

            if (isXmlSerializer)
            {
                return(XmlSerializerOperationBehavior.CreateOperationFormatter(operation, (XmlSerializerFormatAttribute)formatAttribute));
            }
            else
            {
                return(new DataContractSerializerOperationFormatter(operation, (DataContractFormatAttribute)formatAttribute, null));
            }
        }
示例#12
0
        private static void MergeWsdl(WsdlNS.ServiceDescription singleWsdl, WsdlNS.ServiceDescription wsdl, Dictionary <XmlQualifiedName, XmlQualifiedName> bindingReferenceChanges)
        {
            if (wsdl.Services.Count > 0)
            {
                singleWsdl.Name = wsdl.Name;
            }

            foreach (WsdlNS.Binding binding in wsdl.Bindings)
            {
                string uniqueBindingName = NamingHelper.GetUniqueName(binding.Name, WsdlHelper.IsBindingNameUsed, singleWsdl.Bindings);
                if (binding.Name != uniqueBindingName)
                {
                    bindingReferenceChanges.Add(
                        new XmlQualifiedName(binding.Name, binding.ServiceDescription.TargetNamespace),
                        new XmlQualifiedName(uniqueBindingName, singleWsdl.TargetNamespace));
                    UpdatePolicyKeys(binding, uniqueBindingName, wsdl);
                    binding.Name = uniqueBindingName;
                }

                singleWsdl.Bindings.Add(binding);
            }

            foreach (object extension in wsdl.Extensions)
            {
                singleWsdl.Extensions.Add(extension);
            }

            foreach (WsdlNS.Message message in wsdl.Messages)
            {
                singleWsdl.Messages.Add(message);
            }

            foreach (WsdlNS.Service service in wsdl.Services)
            {
                singleWsdl.Services.Add(service);
            }

            foreach (string warning in wsdl.ValidationWarnings)
            {
                singleWsdl.ValidationWarnings.Add(warning);
            }
        }
示例#13
0
        internal ChannelEndpointElement WriteChannelDescription(ServiceEndpoint endpoint, string typeName)
        {
            ChannelEndpointElement channelElement = null;

            // Create Binding
            BindingDictionaryValue bindingDV = CreateBindingConfig(endpoint.Binding);


            channelElement = new ChannelEndpointElement(endpoint.Address, typeName);

            // [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
            // does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
            channelElement.Name = NamingHelper.GetUniqueName(NamingHelper.CodeName(endpoint.Name), this.CheckIfChannelNameInUse, null);

            channelElement.BindingConfiguration = bindingDV.BindingName;
            channelElement.Binding = bindingDV.BindingSectionName;
            channels.Add(channelElement);

            return(channelElement);
        }
示例#14
0
        BindingDictionaryValue CreateBindingConfig(Binding binding)
        {
            BindingDictionaryValue bindingDV;

            if (!bindingTable.TryGetValue(binding, out bindingDV))
            {
                // [....]: review: Use decoded form to preserve the user-given friendly name, however, beacuse our Encoding algorithm
                // does not touch ASCII names, a name that looks like encoded name will not roundtrip(Example: "_x002C_" will turned into ",")
                string bindingName = NamingHelper.GetUniqueName(NamingHelper.CodeName(binding.Name), this.CheckIfBindingNameInUse, null);
                string bindingSectionName;

                if (!BindingsSection.TryAdd(bindingName, binding, config, out bindingSectionName))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.ConfigBindingCannotBeConfigured), "endpoint.Binding"));
                }

                bindingDV = new BindingDictionaryValue(bindingName, bindingSectionName);
                bindingTable.Add(binding, bindingDV);
            }
            return(bindingDV);
        }
            void AddServiceContractAttribute(ServiceContractGenerationContext context)
            {
                CodeAttributeDeclaration serviceContractAttr = new CodeAttributeDeclaration(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ServiceContractAttribute)));

                if (context.ContractType.Name != context.Contract.CodeName)
                {
                    // make sure that decoded Contract name can be used, if not, then override name with encoded value
                    // specified in wsdl; this only works beacuse our Encoding algorithm will leave alredy encoded names untouched
                    string friendlyName = NamingHelper.XmlName(context.Contract.CodeName) == context.Contract.Name ? context.Contract.CodeName : context.Contract.Name;
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(friendlyName)));
                }

                if (NamingHelper.DefaultNamespace != context.Contract.Namespace)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(context.Contract.Namespace)));
                }

                serviceContractAttr.Arguments.Add(new CodeAttributeArgument("ConfigurationName", new CodePrimitiveExpression(NamespaceHelper.GetCodeTypeReference(context.Namespace, context.ContractType).BaseType)));

                if (context.Contract.HasProtectionLevel)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("ProtectionLevel",
                                                                                new CodeFieldReferenceExpression(
                                                                                    new CodeTypeReferenceExpression(typeof(ProtectionLevel)), context.Contract.ProtectionLevel.ToString())));
                }

                if (context.DuplexCallbackType != null)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(context.DuplexCallbackTypeReference)));
                }

                if (context.Contract.SessionMode != SessionMode.Allowed)
                {
                    serviceContractAttr.Arguments.Add(new CodeAttributeArgument("SessionMode",
                                                                                new CodeFieldReferenceExpression(
                                                                                    new CodeTypeReferenceExpression(typeof(SessionMode)), context.Contract.SessionMode.ToString())));
                }

                context.ContractType.CustomAttributes.Add(serviceContractAttr);
            }
        private static CodeMemberMethod CreateBeginOperationMethod(ServiceContractGenerationContext context, CodeTypeDeclaration clientType, string syncMethodName, CodeMemberMethod beginMethod)
        {
            CodeMemberMethod method = new CodeMemberMethod {
                Attributes = MemberAttributes.Private,
                ReturnType = new CodeTypeReference(asyncResultType),
                Name       = NamingHelper.GetUniqueName(GetBeginOperationMethodName(syncMethodName), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations)
            };
            CodeParameterDeclarationExpression expression = new CodeParameterDeclarationExpression {
                Type = new CodeTypeReference(objectArrayType),
                Name = NamingHelper.GetUniqueName("inValues", new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), beginMethod)
            };

            method.Parameters.Add(expression);
            CodeMethodInvokeExpression expression2  = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), beginMethod.Name, new CodeExpression[0]);
            CodeExpression             targetObject = new CodeVariableReferenceExpression(expression.Name);

            for (int i = 0; i < (beginMethod.Parameters.Count - 2); i++)
            {
                CodeVariableDeclarationStatement statement;
                statement = new CodeVariableDeclarationStatement {
                    Type           = beginMethod.Parameters[i].Type,
                    Name           = beginMethod.Parameters[i].Name,
                    InitExpression = new CodeCastExpression(statement.Type, new CodeArrayIndexerExpression(targetObject, new CodeExpression[] { new CodePrimitiveExpression(i) }))
                };
                method.Statements.Add(statement);
                expression2.Parameters.Add(new CodeDirectionExpression(beginMethod.Parameters[i].Direction, new CodeVariableReferenceExpression(statement.Name)));
            }
            for (int j = beginMethod.Parameters.Count - 2; j < beginMethod.Parameters.Count; j++)
            {
                method.Parameters.Add(new CodeParameterDeclarationExpression(beginMethod.Parameters[j].Type, beginMethod.Parameters[j].Name));
                expression2.Parameters.Add(new CodeVariableReferenceExpression(beginMethod.Parameters[j].Name));
            }
            method.Statements.Add(new CodeMethodReturnStatement(expression2));
            clientType.Members.Add(method);
            return(method);
        }
示例#17
0
        static internal XmlName GetOperationName(MethodInfo method)
        {
            OperationContractAttribute operationAttribute = GetOperationContractAttribute(method);

            return(NamingHelper.GetOperationName(GetLogicalName(method), operationAttribute.Name));
        }
        private static CodeMethodReturnStatement GenerateParameters(CodeMemberMethod helperMethod, CodeTypeDeclaration codeTypeDeclaration, CodeExpression target, FieldDirection dir)
        {
            CodeMethodReturnStatement statement = null;

            foreach (CodeTypeMember member in codeTypeDeclaration.Members)
            {
                CodeMemberField field = member as CodeMemberField;
                if (field != null)
                {
                    CodeFieldReferenceExpression left     = new CodeFieldReferenceExpression(target, field.Name);
                    CodeTypeDeclaration          codeType = ServiceContractGenerator.NamespaceHelper.GetCodeType(field.Type);
                    if (codeType != null)
                    {
                        if (dir == FieldDirection.In)
                        {
                            helperMethod.Statements.Add(new CodeAssignStatement(left, new CodeObjectCreateExpression(field.Type, new CodeExpression[0])));
                        }
                        statement = GenerateParameters(helperMethod, codeType, left, dir);
                    }
                    else
                    {
                        CodeParameterDeclarationExpression expression2 = GetRefParameter(helperMethod.Parameters, dir, field);
                        if (((expression2 == null) && (dir == FieldDirection.Out)) && (helperMethod.ReturnType.BaseType == voidTypeRef.BaseType))
                        {
                            helperMethod.ReturnType = field.Type;
                            statement = new CodeMethodReturnStatement(left);
                        }
                        else
                        {
                            if (expression2 == null)
                            {
                                expression2 = new CodeParameterDeclarationExpression(field.Type, NamingHelper.GetUniqueName(field.Name, new NamingHelper.DoesNameExist(ClientClassGenerator.DoesParameterNameExist), helperMethod))
                                {
                                    Direction = dir
                                };
                                helperMethod.Parameters.Add(expression2);
                            }
                            if (dir == FieldDirection.Out)
                            {
                                helperMethod.Statements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression(expression2.Name), left));
                            }
                            else
                            {
                                helperMethod.Statements.Add(new CodeAssignStatement(left, new CodeArgumentReferenceExpression(expression2.Name)));
                            }
                        }
                    }
                }
            }
            return(statement);
        }
        void IServiceContractGenerationExtension.GenerateContract(ServiceContractGenerationContext context)
        {
            CodeTypeDeclaration clientType = context.TypeFactory.CreateClassType();

            clientType.Name = NamingHelper.GetUniqueName(GetClientClassName(context.ContractType.Name), new NamingHelper.DoesNameExist(ClientClassGenerator.DoesMethodNameExist), context.Operations);
            CodeTypeReference contractTypeReference = context.ContractTypeReference;

            if (context.DuplexCallbackType == null)
            {
                clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(ClientBase <>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference }));
            }
            else
            {
                clientType.BaseTypes.Add(new CodeTypeReference(context.ServiceContractGenerator.GetCodeTypeReference(typeof(DuplexClientBase <>)).BaseType, new CodeTypeReference[] { context.ContractTypeReference }));
            }
            clientType.BaseTypes.Add(context.ContractTypeReference);
            if (ClientCtorParamNames.Length != ClientCtorParamTypes.Length)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0])));
            }
            for (int i = 0; i < ClientCtorParamNames.Length; i++)
            {
                if (ClientCtorParamNames[i].Length != ClientCtorParamTypes[i].Length)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid client generation constructor table initialization", new object[0])));
                }
                CodeConstructor constructor = new CodeConstructor {
                    Attributes = MemberAttributes.Public
                };
                if (context.DuplexCallbackType != null)
                {
                    constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(InstanceContext), inputInstanceName));
                    constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(inputInstanceName));
                }
                for (int j = 0; j < ClientCtorParamNames[i].Length; j++)
                {
                    constructor.Parameters.Add(new CodeParameterDeclarationExpression(ClientCtorParamTypes[i][j], ClientCtorParamNames[i][j]));
                    constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(ClientCtorParamNames[i][j]));
                }
                clientType.Members.Add(constructor);
            }
            foreach (OperationContractGenerationContext context2 in context.Operations)
            {
                if (!context2.Operation.IsServerInitiated())
                {
                    CodeTypeReference declaringTypeReference = context2.DeclaringTypeReference;
                    GenerateClientClassMethod(clientType, contractTypeReference, context2.SyncMethod, this.tryAddHelperMethod, declaringTypeReference);
                    if (context2.IsAsync)
                    {
                        CodeMemberMethod beginMethod = GenerateClientClassMethod(clientType, contractTypeReference, context2.BeginMethod, this.tryAddHelperMethod, declaringTypeReference);
                        CodeMemberMethod endMethod   = GenerateClientClassMethod(clientType, contractTypeReference, context2.EndMethod, this.tryAddHelperMethod, declaringTypeReference);
                        if (this.generateEventAsyncMethods)
                        {
                            GenerateEventAsyncMethods(context, clientType, context2.SyncMethod.Name, beginMethod, endMethod);
                        }
                    }
                }
            }
            context.Namespace.Types.Add(clientType);
            context.ClientType          = clientType;
            context.ClientTypeReference = ServiceContractGenerator.NamespaceHelper.GetCodeTypeReference(context.Namespace, clientType);
        }
示例#20
0
 private string GetUniqueMessageName(System.Web.Services.Description.ServiceDescription wsdl, string messageNameBase)
 {
     return(NamingHelper.GetUniqueName(messageNameBase, new NamingHelper.DoesNameExist(MessageContractExporter.DoesMessageNameExist), wsdl));
 }