internal static bool Check(SoapFaultBinding soapFaultBinding, FaultBinding faultBinding, WsdlWarningHandler warningHandler)
 {
     if (string.IsNullOrEmpty(soapFaultBinding.Name))
     {
         string str = System.ServiceModel.SR.GetString("XsdMissingRequiredAttribute1", new object[] { "name" });
         string warning = System.ServiceModel.SR.GetString("IgnoreSoapFaultBinding3", new object[] { faultBinding.OperationBinding.Name, faultBinding.OperationBinding.Binding.ServiceDescription.TargetNamespace, str });
         warningHandler(warning);
         return false;
     }
     return true;
 }
            static WsdlNS.SoapFaultBinding ConvertSoapFaultBinding(WsdlNS.SoapFaultBinding src, EnvelopeVersion version)
            {
                if (version == EnvelopeVersion.None)
                {
                    return(null);
                }

                if (GetBindingVersion <WsdlNS.Soap12FaultBinding>(src) == version)
                {
                    return(src);
                }

                WsdlNS.SoapFaultBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12FaultBinding() : new WsdlNS.SoapFaultBinding();
                if (src != null)
                {
                    dest.Encoding  = src.Encoding;
                    dest.Name      = src.Name;
                    dest.Namespace = src.Namespace;
                    dest.Use       = src.Use;
                    dest.Required  = src.Required;
                }
                return(dest);
            }
            internal static bool ConvertSoapMessageBinding(ref object src, EnvelopeVersion version)
            {
                WsdlNS.SoapBodyBinding body = src as WsdlNS.SoapBodyBinding;
                if (body != null)
                {
                    src = ConvertSoapBodyBinding(body, version);
                    return(true);
                }

                WsdlNS.SoapHeaderBinding header = src as WsdlNS.SoapHeaderBinding;
                if (header != null)
                {
                    src = ConvertSoapHeaderBinding(header, version);
                    return(true);
                }

                WsdlNS.SoapFaultBinding fault = src as WsdlNS.SoapFaultBinding;
                if (fault != null)
                {
                    src = ConvertSoapFaultBinding(fault, version);
                    return(true);
                }

                XmlElement element = src as XmlElement;

                if (element != null)
                {
                    if (IsSoapFaultBinding(element))
                    {
                        src = ConvertSoapFaultBinding(element, version);
                        return(true);
                    }
                }

                return(src == null); // "match" only if nothing passed in
            }
        public override void Check(ConformanceCheckContext ctx, OperationBinding value)
        {
            bool r2754 = false;
            bool r2723 = false;

            foreach (FaultBinding fb in value.Faults)
            {
                SoapFaultBinding sfb = (SoapFaultBinding)value.Extensions.Find(typeof(SoapFaultBinding));
                if (sfb == null)
                {
                    continue;
                }
                r2754 |= sfb.Name != fb.Name;
                r2723 |= sfb.Use == SoapBindingUse.Encoded;
            }
            if (r2754)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2754);
            }
            if (r2723)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2723);
            }
        }
        LiteralType GetLiteralBindingType(Binding b)
        {
            SoapBinding      sb    = (SoapBinding)b.Extensions.Find(typeof(SoapBinding));
            SoapBindingStyle style = (sb != null) ? sb.Style : SoapBindingStyle.Document;

            if (style == SoapBindingStyle.Default)
            {
                style = SoapBindingStyle.Document;
            }

            foreach (OperationBinding ob in b.Operations)
            {
                SoapOperationBinding sob = (SoapOperationBinding)ob.Extensions.Find(typeof(SoapOperationBinding));
                if (sob.Style != SoapBindingStyle.Default && sob.Style != style)
                {
                    return(LiteralType.Inconsistent);
                }
                if (ob.Input != null)
                {
                    SoapBodyBinding sbb = (SoapBodyBinding)ob.Input.Extensions.Find(typeof(SoapBodyBinding));
                    if (sbb != null && sbb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapFaultBinding sfb = (SoapFaultBinding)ob.Input.Extensions.Find(typeof(SoapFaultBinding));
                    if (sfb != null && sfb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapHeaderBinding shb = (SoapHeaderBinding)ob.Input.Extensions.Find(typeof(SoapHeaderBinding));
                    if (shb != null && shb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)ob.Input.Extensions.Find(typeof(SoapHeaderFaultBinding));
                    if (shfb != null && shfb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                }
                if (ob.Output != null)
                {
                    SoapBodyBinding sbb = (SoapBodyBinding)ob.Output.Extensions.Find(typeof(SoapBodyBinding));
                    if (sbb != null && sbb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapFaultBinding sfb = (SoapFaultBinding)ob.Input.Extensions.Find(typeof(SoapFaultBinding));
                    if (sfb != null && sfb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapHeaderBinding shb = (SoapHeaderBinding)ob.Input.Extensions.Find(typeof(SoapHeaderBinding));
                    if (shb != null && shb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                    SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)ob.Input.Extensions.Find(typeof(SoapHeaderFaultBinding));
                    if (shfb != null && shfb.Use != SoapBindingUse.Literal)
                    {
                        return(LiteralType.NotLiteral);
                    }
                }
            }
            if (style == SoapBindingStyle.Document)
            {
                return(LiteralType.Document);
            }
            else
            {
                return(LiteralType.Rpc);
            }
        }
        void CheckSoapBindingExtensions(ConformanceCheckContext ctx, Binding value, LiteralType type)
        {
            bool violationNS   = false;
            bool violation2717 = false;
            bool violation2720 = false;
            bool violation2721 = false;

            foreach (OperationBinding op in value.Operations)
            {
                SoapBodyBinding sbb = op.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding;
                if (sbb != null)
                {
                    if (type == LiteralType.Document && sbb.Namespace != null)
                    {
                        violationNS = true;
                    }
                    if (type == LiteralType.Rpc && sbb.Namespace == null)
                    {
                        violation2717 = true;
                    }
                }

                SoapHeaderBinding shb = op.Extensions.Find(typeof(SoapHeaderBinding)) as SoapHeaderBinding;
                if (shb != null)
                {
                    violationNS   |= shb.Namespace != null;
                    violation2720 |= !IsValidPart(shb.Part);
                }

                SoapHeaderFaultBinding sfhb = op.Extensions.Find(typeof(SoapHeaderFaultBinding)) as SoapHeaderFaultBinding;
                if (sfhb != null)
                {
                    violationNS   |= sfhb.Namespace != null;
                    violation2720 |= !IsValidPart(sfhb.Part);
                }

                SoapFaultBinding sfb = op.Extensions.Find(typeof(SoapFaultBinding)) as SoapFaultBinding;
                if (sfb != null)
                {
                    violation2721 |= sfb.Name == null;
                    violationNS   |= sfb.Namespace != null;
                }
            }
            if (violationNS)
            {
                ctx.ReportRuleViolation(value,
                                        type == LiteralType.Document ?
                                        BasicProfileRules.R2716 :
                                        BasicProfileRules.R2726);
            }
            if (violation2717)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2717);
            }
            if (violation2720)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2720);
            }
            if (violation2721)
            {
                ctx.ReportRuleViolation(value, BasicProfileRules.R2721);
            }
        }
Beispiel #7
0
        internal static bool AnalyzeBinding(Binding binding, ServiceDescription description, ServiceDescriptionCollection descriptions, BasicProfileViolationCollection violations)
        {
            bool        flag     = false;
            bool        flag2    = false;
            SoapBinding binding2 = (SoapBinding)binding.Extensions.Find(typeof(SoapBinding));

            if ((binding2 == null) || (binding2.GetType() != typeof(SoapBinding)))
            {
                return(false);
            }
            SoapBindingStyle style = (binding2.Style == SoapBindingStyle.Default) ? SoapBindingStyle.Document : binding2.Style;

            if (binding2.Transport.Length == 0)
            {
                violations.Add("R2701", System.Web.Services.Res.GetString("BindingMissingAttribute", new object[] { binding.Name, description.TargetNamespace, "transport" }));
            }
            else if (binding2.Transport != "http://schemas.xmlsoap.org/soap/http")
            {
                violations.Add("R2702", System.Web.Services.Res.GetString("BindingInvalidAttribute", new object[] { binding.Name, description.TargetNamespace, "transport", binding2.Transport }));
            }
            PortType  portType  = descriptions.GetPortType(binding.Type);
            Hashtable hashtable = new Hashtable();

            if (portType != null)
            {
                foreach (Operation operation in portType.Operations)
                {
                    if (operation.Messages.Flow == OperationFlow.Notification)
                    {
                        violations.Add("R2303", System.Web.Services.Res.GetString("OperationFlowNotification", new object[] { operation.Name, binding.Type.Namespace, binding.Type.Namespace }));
                    }
                    if (operation.Messages.Flow == OperationFlow.SolicitResponse)
                    {
                        violations.Add("R2303", System.Web.Services.Res.GetString("OperationFlowSolicitResponse", new object[] { operation.Name, binding.Type.Namespace, binding.Type.Namespace }));
                    }
                    if (hashtable[operation.Name] != null)
                    {
                        violations.Add("R2304", System.Web.Services.Res.GetString("Operation", new object[] { operation.Name, binding.Type.Name, binding.Type.Namespace }));
                    }
                    else
                    {
                        OperationBinding binding3 = null;
                        foreach (OperationBinding binding4 in binding.Operations)
                        {
                            if (operation.IsBoundBy(binding4))
                            {
                                if (binding3 != null)
                                {
                                    violations.Add("R2304", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding3.Name, binding3.Parent.Name, description.TargetNamespace }));
                                }
                                binding3 = binding4;
                            }
                        }
                        if (binding3 == null)
                        {
                            violations.Add("R2718", System.Web.Services.Res.GetString("OperationMissingBinding", new object[] { operation.Name, binding.Type.Name, binding.Type.Namespace }));
                        }
                        else
                        {
                            hashtable.Add(operation.Name, operation);
                        }
                    }
                }
            }
            Hashtable        wireSignatures = new Hashtable();
            SoapBindingStyle style2         = SoapBindingStyle.Default;

            foreach (OperationBinding binding5 in binding.Operations)
            {
                SoapBindingStyle style3 = style;
                string           name   = binding5.Name;
                if (name != null)
                {
                    if (hashtable[name] == null)
                    {
                        violations.Add("R2718", System.Web.Services.Res.GetString("PortTypeOperationMissing", new object[] { binding5.Name, binding.Name, description.TargetNamespace, binding.Type.Name, binding.Type.Namespace }));
                    }
                    Operation            operation2 = FindOperation(portType.Operations, binding5);
                    SoapOperationBinding binding6   = (SoapOperationBinding)binding5.Extensions.Find(typeof(SoapOperationBinding));
                    if (binding6 != null)
                    {
                        if (style2 == SoapBindingStyle.Default)
                        {
                            style2 = binding6.Style;
                        }
                        flag  |= style2 != binding6.Style;
                        style3 = (binding6.Style != SoapBindingStyle.Default) ? binding6.Style : style;
                    }
                    if (binding5.Input != null)
                    {
                        SoapBodyBinding binding7 = FindSoapBodyBinding(true, binding5.Input.Extensions, violations, style3 == SoapBindingStyle.Document, binding5.Name, binding.Name, description.TargetNamespace);
                        if ((binding7 != null) && (binding7.Use != SoapBindingUse.Encoded))
                        {
                            Message message = (operation2 == null) ? null : ((operation2.Messages.Input == null) ? null : descriptions.GetMessage(operation2.Messages.Input.Message));
                            if (style3 == SoapBindingStyle.Rpc)
                            {
                                CheckMessageParts(message, binding7.Parts, false, binding5.Name, binding.Name, description.TargetNamespace, wireSignatures, violations);
                            }
                            else
                            {
                                flag2 = flag2 || ((binding7.Parts != null) && (binding7.Parts.Length > 1));
                                int num = (binding7.Parts == null) ? 0 : binding7.Parts.Length;
                                CheckMessageParts(message, binding7.Parts, true, binding5.Name, binding.Name, description.TargetNamespace, wireSignatures, violations);
                                if (((num == 0) && (message != null)) && (message.Parts.Count > 1))
                                {
                                    violations.Add("R2210", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding5.Name, binding.Name, description.TargetNamespace }));
                                }
                            }
                        }
                    }
                    if (binding5.Output != null)
                    {
                        SoapBodyBinding binding8 = FindSoapBodyBinding(false, binding5.Output.Extensions, violations, style3 == SoapBindingStyle.Document, binding5.Name, binding.Name, description.TargetNamespace);
                        if ((binding8 != null) && (binding8.Use != SoapBindingUse.Encoded))
                        {
                            Message message2 = (operation2 == null) ? null : ((operation2.Messages.Output == null) ? null : descriptions.GetMessage(operation2.Messages.Output.Message));
                            if (style3 == SoapBindingStyle.Rpc)
                            {
                                CheckMessageParts(message2, binding8.Parts, false, binding5.Name, binding.Name, description.TargetNamespace, null, violations);
                            }
                            else
                            {
                                flag2 = flag2 || ((binding8.Parts != null) && (binding8.Parts.Length > 1));
                                int num2 = (binding8.Parts == null) ? 0 : binding8.Parts.Length;
                                CheckMessageParts(message2, binding8.Parts, true, binding5.Name, binding.Name, description.TargetNamespace, null, violations);
                                if (((num2 == 0) && (message2 != null)) && (message2.Parts.Count > 1))
                                {
                                    violations.Add("R2210", System.Web.Services.Res.GetString("OperationBinding", new object[] { binding5.Name, binding.Name, description.TargetNamespace }));
                                }
                            }
                        }
                    }
                    foreach (FaultBinding binding9 in binding5.Faults)
                    {
                        foreach (ServiceDescriptionFormatExtension extension in binding9.Extensions)
                        {
                            if (extension is SoapFaultBinding)
                            {
                                SoapFaultBinding item = (SoapFaultBinding)extension;
                                if (item.Use == SoapBindingUse.Encoded)
                                {
                                    violations.Add("R2706", MessageString(item, binding5.Name, binding.Name, description.TargetNamespace, false, null));
                                }
                                else
                                {
                                    if ((item.Name == null) || (item.Name.Length == 0))
                                    {
                                        violations.Add("R2721", System.Web.Services.Res.GetString("FaultBinding", new object[] { binding9.Name, binding5.Name, binding.Name, description.TargetNamespace }));
                                    }
                                    else if (item.Name != binding9.Name)
                                    {
                                        violations.Add("R2754", System.Web.Services.Res.GetString("FaultBinding", new object[] { binding9.Name, binding5.Name, binding.Name, description.TargetNamespace }));
                                    }
                                    if ((item.Namespace != null) && (item.Namespace.Length > 0))
                                    {
                                        violations.Add((style3 == SoapBindingStyle.Document) ? "R2716" : "R2726", MessageString(item, binding5.Name, binding.Name, description.TargetNamespace, false, null));
                                    }
                                }
                            }
                        }
                    }
                    if (hashtable[binding5.Name] == null)
                    {
                        violations.Add("R2718", System.Web.Services.Res.GetString("PortTypeOperationMissing", new object[] { binding5.Name, binding.Name, description.TargetNamespace, binding.Type.Name, binding.Type.Namespace }));
                    }
                }
            }
            if (flag2)
            {
                violations.Add("R2201", System.Web.Services.Res.GetString("BindingMultipleParts", new object[] { binding.Name, description.TargetNamespace, "parts" }));
            }
            if (flag)
            {
                violations.Add("R2705", System.Web.Services.Res.GetString("Binding", new object[] { binding.Name, description.TargetNamespace }));
            }
            return(true);
        }
 private void Write112_SoapFaultBinding(string n, string ns, SoapFaultBinding o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(SoapFaultBinding)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("SoapFaultBinding", "http://schemas.xmlsoap.org/wsdl/soap/");
         }
         if (o.Required)
         {
             base.WriteAttribute("required", "http://schemas.xmlsoap.org/wsdl/", XmlConvert.ToString(o.Required));
         }
         if (o.Use != SoapBindingUse.Default)
         {
             base.WriteAttribute("use", "", this.Write98_SoapBindingUse(o.Use));
         }
         base.WriteAttribute("name", "", o.Name);
         base.WriteAttribute("namespace", "", o.Namespace);
         if ((o.Encoding != null) && (o.Encoding.Length != 0))
         {
             base.WriteAttribute("encodingStyle", "", o.Encoding);
         }
         base.WriteEndElement(o);
     }
 }