Example #1
0
        public static void RemoveAllOtherOperations(this ServiceDescription sd, IEnumerable <string> keepOperations)
        {
            foreach (var port in sd.GetPortTypes())
            {
                foreach (var rop in port.GetOperations().Where(op => !keepOperations.Contains(op.Name)).ToList())
                {
                    foreach (OperationMessage opmsg in rop.Messages)
                    {
                        // WARN: namespaces are ignored
                        foreach (var removeMsg in sd.GetMessages().Where(msg => msg.Name == opmsg.Message.Name).ToList())
                        {
                            sd.Messages.Remove(removeMsg);
                        }
                    }

                    foreach (var binding in sd.GetBindings())
                    {
                        foreach (var operationBinding in binding.Operations.Cast <OperationBinding>().Where(op => !keepOperations.Contains(op.Name)).ToList())
                        {
                            binding.Operations.Remove(operationBinding);
                        }
                    }
                    port.Operations.Remove(rop);
                }
            }
        }
Example #2
0
        public static void RemoveUnreferencesMessages(this ServiceDescription sd)
        {
            // Gather messages via bindings
            var operationBindings        = sd.GetBindings().SelectMany(c => c.GetOperationBindings()).ToList();
            var soapHeaderInputMessages  = operationBindings.Select(c => c.Input).SelectMany(c => c.GetExtensions().OfType <SoapHeaderBinding>()).Select(c => c.Message);
            var soapHeaderOutputMessages = operationBindings.Select(c => c.Output).SelectMany(c => c.GetExtensions().OfType <SoapHeaderBinding>()).Select(c => c.Message);

            // Gather messages via port type
            var portOperations = sd.GetPortTypes().SelectMany(c => c.GetOperations()).ToList();

            var operationMessages = portOperations.SelectMany(c => c.GetOperationMessages()).Select(c => c.Message);
            var operationFaults   = portOperations.SelectMany(c => c.GetOperationFaults()).Select(c => c.Message);

            var allMessagesOnAllPorts = operationMessages.Concat(soapHeaderInputMessages).Concat(soapHeaderOutputMessages).Concat(operationFaults).ToList();

            foreach (var messageElement in sd.GetMessages().ToList())
            {
                // WARN: namespaces are ignored
                if (!allMessagesOnAllPorts.Any(c => c.Name == messageElement.Name))
                {
                    sd.Messages.Remove(messageElement);
                }
            }
        }