コード例 #1
0
        void ReflectBinding(ReflectedBinding reflectedBinding)
        {
            string bindingName      = XmlConvert.EncodeLocalName(reflectedBinding.bindingAttr.Name);
            string bindingNamespace = reflectedBinding.bindingAttr.Namespace;

            if (bindingName.Length == 0)
            {
                bindingName = Service.Name + ProtocolName;
            }
            if (bindingNamespace.Length == 0)
            {
                bindingNamespace = ServiceDescription.TargetNamespace;
            }
            WsiProfiles claims = WsiProfiles.None;

            if (reflectedBinding.bindingAttr.Location.Length > 0)
            {
                // If a URL is specified for the WSDL, file, then we just import the
                // binding from there instead of generating it in this WSDL file.
                portType = null;
                binding  = null;
            }
            else
            {
                bindingServiceDescription = GetServiceDescription(bindingNamespace);
                CodeIdentifiers bindingNames = new CodeIdentifiers();
                foreach (Binding b in bindingServiceDescription.Bindings)
                {
                    bindingNames.AddReserved(b.Name);
                }

                bindingName = bindingNames.AddUnique(bindingName, binding);

                portType      = new PortType();
                binding       = new Binding();
                portType.Name = bindingName;
                binding.Name  = bindingName;
                binding.Type  = new XmlQualifiedName(portType.Name, bindingNamespace);
                claims        = reflectedBinding.bindingAttr.ConformsTo & this.ConformsTo;
                if (reflectedBinding.bindingAttr.EmitConformanceClaims && claims != WsiProfiles.None)
                {
                    ServiceDescription.AddConformanceClaims(binding.GetDocumentationElement(), claims);
                }
                bindingServiceDescription.Bindings.Add(binding);
                bindingServiceDescription.PortTypes.Add(portType);
            }

            if (portNames == null)
            {
                portNames = new CodeIdentifiers();
                foreach (Port p in Service.Ports)
                {
                    portNames.AddReserved(p.Name);
                }
            }

            port         = new Port();
            port.Binding = new XmlQualifiedName(bindingName, bindingNamespace);
            port.Name    = portNames.AddUnique(bindingName, port);
            Service.Ports.Add(port);

            BeginClass();

            if (reflectedBinding.methodList != null && reflectedBinding.methodList.Count > 0)
            {
                foreach (LogicalMethodInfo method in reflectedBinding.methodList)
                {
                    MoveToMethod(method);

                    operation      = new Operation();
                    operation.Name = XmlConvert.EncodeLocalName(method.Name);
                    if (methodAttr.Description != null && methodAttr.Description.Length > 0)
                    {
                        operation.Documentation = methodAttr.Description;
                    }

                    operationBinding      = new OperationBinding();
                    operationBinding.Name = operation.Name;

                    inputMessage   = null;
                    outputMessage  = null;
                    headerMessages = null;

                    if (ReflectMethod())
                    {
                        if (inputMessage != null)
                        {
                            bindingServiceDescription.Messages.Add(inputMessage);
                        }
                        if (outputMessage != null)
                        {
                            bindingServiceDescription.Messages.Add(outputMessage);
                        }
                        if (headerMessages != null)
                        {
                            foreach (Message headerMessage in headerMessages)
                            {
                                bindingServiceDescription.Messages.Add(headerMessage);
                            }
                        }
                        binding.Operations.Add(operationBinding);
                        portType.Operations.Add(operation);
                    }
                }
            }
            if (binding != null && claims == WsiProfiles.BasicProfile1_1 && ProtocolName == "Soap")
            {
                BasicProfileViolationCollection warnings = new BasicProfileViolationCollection();
                WebServicesInteroperability.AnalyzeBinding(binding, bindingServiceDescription, ServiceDescriptions, warnings);
                if (warnings.Count > 0)
                {
                    throw new InvalidOperationException(Res.GetString(Res.WebWsiViolation, ServiceType.FullName, warnings.ToString()));
                }
            }
            EndClass();
        }