static void ImportMessageSoapAction(WsdlContractConversionContext contractContext, MessageDescription message, MessageBinding wsdlMessageBinding, bool isResponse)
        {
            string soapAction = SoapHelper.ReadSoapAction(wsdlMessageBinding.OperationBinding);

            if (contractContext != null)
            {
                OperationMessage wsdlOperationMessage = contractContext.GetOperationMessage(message);
                string           wsaAction            = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationMessage);
                if (wsaAction == null && soapAction != null)
                {
                    if (isResponse)
                    {
                        message.Action = "*";
                    }
                    else
                    {
                        message.Action = soapAction;
                    }
                }
                //
            }
            else
            {
                //
            }
        }
Example #2
0
 public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     if (this.Enable)
     {
         XsdDataContractExporter dataContractExporter;
         object dataContractExporterObj = null;
         if (exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporterObj))
         {
             dataContractExporter = dataContractExporterObj as XsdDataContractExporter;
         }
         else
         {
             XmlSchemaSet set = exporter.GeneratedXmlSchemas;
             //Annotation.GetSchemaAnnotation(set);
             //set.Compile();
             dataContractExporter = new XsdDataContractExporter(set);
             exporter.State.Add(typeof(XsdDataContractExporter), dataContractExporter);
         }
         if (dataContractExporter.Options == null)
         {
             dataContractExporter.Options = new ExportOptions();
         }
         if (dataContractExporter.Options.DataContractSurrogate == null)
         {
             dataContractExporter.Options.DataContractSurrogate = new DataContractAnnotationSurrogate()
             {
                 ExportAsText = this.ExportAsText, IsBehaviorExtension = this.IsBehaviorExtensions
             }
         }
         ;
     }
 }
Example #3
0
        public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            if (exporter == null)
            {
                throw new ArgumentNullException("exporter");
            }

            object dataContractExporter;
            XsdDataContractExporter xsdDCExporter;

            if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter))
            {
                xsdDCExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas);
                exporter.State.Add(typeof(XsdDataContractExporter), xsdDCExporter);
            }
            else
            {
                xsdDCExporter = (XsdDataContractExporter)dataContractExporter;
            }
            if (xsdDCExporter.Options == null)
            {
                xsdDCExporter.Options = new ExportOptions();
            }

            if (xsdDCExporter.Options.DataContractSurrogate == null)
            {
                xsdDCExporter.Options.DataContractSurrogate = new AllowNonSerializableTypesSurrogate();
            }
        }
        private static void ImportMessageSoapAction(WsdlContractConversionContext contractContext, MessageDescription message, MessageBinding wsdlMessageBinding, bool isResponse)
        {
            string soapAction = SoapHelper.ReadSoapAction(wsdlMessageBinding.OperationBinding);

            if (contractContext != null)
            {
                OperationMessage wsdlOperationMessage = contractContext.GetOperationMessage(message);
                string           wsaAction            = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationMessage);
                if (wsaAction == null && soapAction != null)
                {
                    if (isResponse)
                    {
                        message.Action = "*";
                    }
                    else
                    {
                        message.Action = soapAction;
                    }
                }
                //CONSIDER, hsomu: If WS-Addressing action was found, we should verify that it is the same as the SOAP action
                //      (for the request message).
            }
            else
            {
                //CONSIDER, hsomu: verify SOAP action matches referenced contract.operation.message
            }
        }
Example #5
0
        /// <summary>
        /// When ExportContract is called to generate the necessary metadata, we inspect the service
        /// contract and build a list of parameters that we'll need to adjust the XSD for later.
        /// </summary>
        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            _requiredParameter = new List <RequiredMessagePart>();

            foreach (var operation in context.Contract.Operations)
            {
                var inputMessage = operation.Messages.Where(m => m.Direction == MessageDirection.Input).First();
                var parameters   = operation.SyncMethod.GetParameters();
                Debug.Assert(parameters.Length == inputMessage.Body.Parts.Count);

                for (int i = 0; i < parameters.Length; i++)
                {
                    object[] attributes = parameters[i].GetCustomAttributes(typeof(OptionalAttribute), false);
                    if (attributes.Length == 0)
                    {
                        // The parameter has no [Optional] attribute, add it to the list of parameters
                        // that we need to adjust the XML schema for later on.
                        _requiredParameter.Add(new RequiredMessagePart()
                        {
                            Namespace = inputMessage.Body.Parts[i].Namespace,
                            Message   = operation.Name,
                            Name      = inputMessage.Body.Parts[i].Name
                        });
                    }
                }
            }
        }
Example #6
0
 //
 // IWsdlExportExtension Implementation
 //
 public void ExportContract(
     WsdlExporter exporter,
     WsdlContractConversionContext context
     )
 {
     // never called
 }
Example #7
0
        internal static void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context, XmlCommentFormat format)
        {
            InitXsdDataContractExporter(exporter, format);

            XmlDocument commentsDoc = XmlCommentsUtils.LoadXmlComments(context.Contract.ContractType, true);

            if (commentsDoc == null)
            {
                return;
            }

            string comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, context.Contract.ContractType, format);

            if (comment != null)
            {
                context.WsdlPortType.Documentation = comment;
            }

            foreach (Operation op in context.WsdlPortType.Operations)
            {
                OperationDescription opDescription = context.GetOperationDescription(op);
                MemberInfo           mi            = opDescription.SyncMethod;
                if (mi == null)
                {
                    mi = opDescription.BeginMethod;
                }
                comment = XmlCommentsUtils.GetFormattedComment(commentsDoc, mi, format);
                if (comment != null)
                {
                    op.Documentation = comment;
                }
            }
        }
        /// <summary>
        /// When ExportContract is called to generate the necessary metadata, we inspect the service
        /// contract and build a list of parameters that we'll need to adjust the XSD for later.
        /// </summary>
        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            _Namespaces = new Dictionary <string, XSDNamespace>();

            if (!string.IsNullOrWhiteSpace(HeaderComment))
            {
                context.WsdlPortType.Documentation = string.Empty;

                XmlDocument owner          = context.WsdlPortType.DocumentationElement.OwnerDocument;
                XmlElement  summaryElement = owner.CreateElement("summary");
                summaryElement.InnerText = HeaderComment;
                context.WsdlPortType.DocumentationElement.AppendChild(summaryElement);
            }

            foreach (var operation in context.Contract.Operations)
            {
                foreach (MessageDescription message in operation.Messages.Where(m => m.Direction == MessageDirection.Input))
                {
                    var parameters = operation.SyncMethod.GetParameters();
                    Debug.Assert(parameters.Length == message.Body.Parts.Count);

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        foreach (PropertyInfo pi in parameters[i].ParameterType.GetProperties())
                        {
                            ExtractAttributes(pi, message, operation, message.Body.Parts[0]);
                        }
                    }
                }
            }
        }
 public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
 {
     foreach (Operation operation in context.WsdlPortType.Operations)
     {
         var operationDescription = context.GetOperationDescription(operation);
         operationDescription.OperationBehaviors.Add(this);
     }
 }
        private static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding)
        {
            string str = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding);

            if (((contractContext != null) && (WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(contractContext.GetOperationFault(fault)) == null)) && (str != null))
            {
                fault.Action = str;
            }
        }
 public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     if (_dcs != null && _dcs is IWsdlExportExtension)
     {
         ((IWsdlExportExtension)_dcs).ExportContract(exporter, context);
     }
     else if (_xcs != null && _xcs is IWsdlExportExtension)
     {
         ((IWsdlExportExtension)_xcs).ExportContract(exporter, context);
     }
 }
Example #12
0
        public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                var description = context.Contract.Operations.Find(operation.Name);
                if (description == null)
                {
                    continue;
                }

                description.OperationBehaviors.Add(this);
            }
        }
Example #13
0
 internal static void Export(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     foreach (OperationDescription op in context.Contract.Operations)
     {
         SoapHeaderAttribute[] soapHeaders = (SoapHeaderAttribute[])op.SyncMethod.GetCustomAttributes(typeof(SoapHeaderAttribute), false);
         if (soapHeaders.Length > 0)
         {
             foreach (SoapHeaderAttribute soapHeader in soapHeaders)
             {
                 AddSoapHeader(op, soapHeader);
             }
         }
     }
 }
Example #14
0
        /// <summary>Called when importing a contract.</summary>
        /// <param name="importer">The importer.</param>
        /// <param name="context">The import context to be modified.</param>
        public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            // Ensure that the client class has been appropriately created in order for us to add methods to it.
            context.Contract.Behaviors.Add(new TaskAsyncServiceContractGenerationExtension());

            // For each operation, add a task-based async equivalent.
            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                var description = context.Contract.Operations.Find(operation.Name);
                if (description != null)
                {
                    description.Behaviors.Add(new TaskAsyncOperationContractGenerationExtension());
                }
            }
        }
Example #15
0
 /// <summary>
 /// When the contract is exported, we add "CyclicReferencesAwareAttribute" to the export so that the WSDL importer knows
 /// where to add the attribute on the client side.  Yes, I'll admit it's a little kludge, but it seems to work.
 /// </summary>
 /// <param name="exporter"></param>
 /// <param name="context"></param>
 public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     if (_contractDescription != null)
     {
         context.WsdlPortType.Documentation = "CyclicReferencesAwareAttribute";
     }
     else
     {
         Operation operation = context.GetOperation(_operationDescription);
         if (operation != null)
         {
             operation.Documentation = "CyclicReferencesAwareAttribute";
         }
     }
 }
        private static void ImportMessageSoapAction(WsdlContractConversionContext contractContext, MessageDescription message, MessageBinding wsdlMessageBinding, bool isResponse)
        {
            string str = SoapHelper.ReadSoapAction(wsdlMessageBinding.OperationBinding);

            if (((contractContext != null) && (WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(contractContext.GetOperationMessage(message)) == null)) && (str != null))
            {
                if (isResponse)
                {
                    message.Action = "*";
                }
                else
                {
                    message.Action = str;
                }
            }
        }
Example #17
0
        void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            string documentation = GetDocumentation(context.WsdlPortType);

            context.Contract.Behaviors.Add(new XmlCommentsSvcExtension(this, documentation));

            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                documentation = GetDocumentation(operation);
                if (!String.IsNullOrEmpty(documentation))
                {
                    OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
                    operationDescription.Behaviors.Add(new XmlCommentsOpExtension(this, documentation));
                }
            }
        }
        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            // Build the custom header description
            var headerDescription = new MessageHeaderDescription(CustomHeader.Name, CustomHeader.Namespace);

            headerDescription.Type = typeof(CustomHeader);

            // Loop through all the operations defined for the contract and add custom SOAP header to the WSDL
            foreach (OperationDescription op in context.Contract.Operations)
            {
                foreach (MessageDescription messageDescription in op.Messages)
                {
                    messageDescription.Headers.Add(headerDescription);
                }
            }
        }
 void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     // This is either for a service contract or operation, so set documentation accordingly.
     if (_contractDescription != null)
     {
         // Attribute was applied to a contract.
         context.WsdlPortType.Documentation = this.Text;
     }
     else
     {
         // Attribute was applied to an operation.
         Operation operation = context.GetOperation(_operationDescription);
         if (operation != null)
         {
             operation.Documentation = this.Text;
         }
     }
 }
Example #20
0
 public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
 {
     // Operation Documentation
     foreach (Operation operation in context.WsdlPortType.Operations)
     {
         // Operations with the CyclicReferencesAwareAttribute should have a documentation item
         // See CyclicReferencesAwareAttribute::ExportContract for more info
         if (operation.Documentation != null && operation.Documentation == "CyclicReferencesAwareAttribute")
         {
             OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
             if (operationDescription != null)
             {
                 // System examines the operation behaviors to see whether any implement IWsdlImportExtension.
                 operationDescription.Behaviors.Add(new CyclicReferencesAwareAttributeImporter());
             }
         }
     }
 }
        static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding)
        {
            string soapAction = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding);

            if (contractContext != null)
            {
                OperationFault wsdlOperationFault = contractContext.GetOperationFault(fault);
                string         wsaAction          = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationFault);
                if (wsaAction == null && soapAction != null)
                {
                    fault.Action = soapAction;
                }
                //
            }
            else
            {
                //
            }
        }
        private static void ImportFaultSoapAction(WsdlContractConversionContext contractContext, FaultDescription fault, FaultBinding wsdlFaultBinding)
        {
            string soapAction = SoapHelper.ReadSoapAction(wsdlFaultBinding.OperationBinding);

            if (contractContext != null)
            {
                OperationFault wsdlOperationFault = contractContext.GetOperationFault(fault);
                string         wsaAction          = WsdlImporter.WSAddressingHelper.FindWsaActionAttribute(wsdlOperationFault);
                if (wsaAction == null && soapAction != null)
                {
                    fault.Action = soapAction;
                }
                //CONSIDER, hsomu: If WS-Addressing action was found, we should verify that it is the same as the SOAP action
                //      (for the request message).
            }
            else
            {
                //CONSIDER, hsomu: verify SOAP action matches referenced contract.operation.message
            }
        }
 // <snippet4>
 public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
 {
     Console.Write("ImportContract");
     // Contract Documentation
     if (context.WsdlPortType.Documentation != null)
     {
         context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation));
     }
     // Operation Documentation
     foreach (Operation operation in context.WsdlPortType.Operations)
     {
         if (operation.Documentation != null)
         {
             OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
             if (operationDescription != null)
             {
                 operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation));
             }
         }
     }
 }
Example #24
0
        public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            // Contract documentation

            if (context.WsdlPortType.Documentation != null)
            {
                context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.DocumentationElement));
            }

            // Operation documentation
            foreach (Operation operation in context.WsdlPortType.Operations)
            {
                if (operation.Documentation == null)
                {
                    continue;
                }
                var operationDescription = context.Contract.Operations.Find(operation.Name);

                operationDescription?.Behaviors.Add(new WsdlDocumentationImporter(operation.DocumentationElement));
            }
        }
        void IWsdlImportExtension.ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
        {
            Dictionary <string, MessageHeaderDescription> allHeaders = new Dictionary <string, MessageHeaderDescription>();

            foreach (OperationDescription op in context.Contract.Operations)
            {
                Dictionary <string, SoapHeaderDirection> headerTypes = new Dictionary <string, SoapHeaderDirection>();
                List <MessageHeaderDescription>          headers     = new List <MessageHeaderDescription>();
                foreach (MessageDescription msg in op.Messages)
                {
                    foreach (MessageHeaderDescription msgHeader in msg.Headers)
                    {
                        SoapHeaderDirection direction = MessageDirectionToSoapHeaderDirection(msg.Direction);
                        SoapHeaderDirection currentDirection;
                        if (headerTypes.TryGetValue(msgHeader.Name, out currentDirection))
                        {
                            headerTypes[msgHeader.Name] = currentDirection | direction;
                        }
                        else
                        {
                            headers.Add(msgHeader);
                            headerTypes[msgHeader.Name] = direction;
                        }
                    }
                    msg.Headers.Clear();
                }

                Dictionary <MessageHeaderDescription, SoapHeaderDirection> msgHeaders = new Dictionary <MessageHeaderDescription, SoapHeaderDirection>();
                foreach (MessageHeaderDescription msgHeader in headers)
                {
                    msgHeaders[msgHeader]      = headerTypes[msgHeader.Name];
                    allHeaders[msgHeader.Name] = msgHeader;
                }
                op.Behaviors.Add(new SoapHeaderOpExtension(msgHeaders));
            }
            if (allHeaders.Count > 0) //If any Soap header exists, mark the contract with SoapHeaders attribute
            {
                context.Contract.Behaviors.Add(new SoapHeaderSvcExtension(allHeaders));
            }
        }
        private void ReplaceEnumerationClassParametersWithEnums(WsdlContractConversionContext context)
        {
            foreach (var operation in context.Contract.Operations)
            {
                foreach (var message in operation.Messages)
                {
                    foreach (var part in message.Body.Parts)
                    {
                        if (part.Type.IsAssignableFrom(typeof(Expression)))
                        {
                            part.Type = typeof(ExpressionNode);
                        }

                        //Type enumType;
                        //if (this.surrogate.Generator.TryGetEnumByType(part.Type, out enumType))
                        //{
                        //    part.Type = enumType;
                        //}
                    }
                }
            }
        }
 public void ImportContract(WsdlImporter importer, WsdlContractConversionContext context)
 {
     // Contract Documentation
     if (context.WsdlPortType.Documentation != null)
     {
         // System examines the contract behaviors to see whether any implement IWsdlImportExtension.
         context.Contract.Behaviors.Add(new WsdlDocumentationImporter(context.WsdlPortType.Documentation));
     }
     // Operation Documentation
     foreach (Operation operation in context.WsdlPortType.Operations)
     {
         if (operation.Documentation != null)
         {
             OperationDescription operationDescription = context.Contract.Operations.Find(operation.Name);
             if (operationDescription != null)
             {
                 // System examines the operation behaviors to see whether any implement IWsdlImportExtension.
                 operationDescription.Behaviors.Add(new WsdlDocumentationImporter(operation.Documentation));
             }
         }
     }
 }
Example #28
0
        public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
        {
            XsdDataContractExporter xsdInventoryExporter;
            object dataContractExporter;

            if (!exporter.State.TryGetValue(typeof(XsdDataContractExporter), out dataContractExporter))
            {
                xsdInventoryExporter = new XsdDataContractExporter(exporter.GeneratedXmlSchemas);
                exporter.State.Add(typeof(XsdDataContractExporter), xsdInventoryExporter);
            }
            else
            {
                xsdInventoryExporter = (XsdDataContractExporter)dataContractExporter;
            }

            if (xsdInventoryExporter.Options == null)
            {
                xsdInventoryExporter.Options = new ExportOptions();
            }

            xsdInventoryExporter.Options.DataContractSurrogate = this.surrogate;
        }
 void IWsdlExportExtension.ExportContract(WsdlExporter exporter,
                                          WsdlContractConversionContext context)
 {
     throw new NotImplementedException();
 }
 public void ExportContract(WsdlExporter exporter, WsdlContractConversionContext context)
 {
     ((IWsdlExportExtension)InnerMessageEncodingBindingElement).ExportContract(exporter, context);
 }