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);
            }
        }
        void CheckMessageBinding(ConformanceCheckContext ctx, Hashtable portParts, MessageBinding value)
        {
            SoapBodyBinding sbb = (SoapBodyBinding)value.Extensions.Find(typeof(SoapBodyBinding));
            Message         msg = FindMessage(ctx, value);
            LiteralType     bt  = GetLiteralBindingType(value.OperationBinding.Binding);

            if (sbb != null)
            {
                if (bt == LiteralType.Document)
                {
                    if (sbb.Parts != null && sbb.Parts.Length > 1)
                    {
                        ctx.ReportRuleViolation(value, BasicProfileRules.R2201);
                    }

                    if (sbb.Parts == null)
                    {
                        if (msg.Parts != null && msg.Parts.Count > 1)
                        {
                            ctx.ReportRuleViolation(value, BasicProfileRules.R2210);
                        }
                        if (msg.Parts.Count == 1)
                        {
                            portParts.Remove(msg.Parts[0]);
                        }
                    }
                    else
                    {
                        if (sbb.Parts.Length == 0 && msg.Parts.Count == 1)
                        {
                            portParts.Remove(msg.Parts[0]);
                        }
                        else
                        {
                            foreach (string part in sbb.Parts)
                            {
                                MessagePart mp = msg.FindPartByName(part);
                                portParts.Remove(mp);
                                if (!mp.DefinedByElement)
                                {
                                    ctx.ReportRuleViolation(value, BasicProfileRules.R2204);
                                }
                            }
                        }
                    }
                }
                else if (bt == LiteralType.Rpc)
                {
                    if (sbb.Parts != null)
                    {
                        foreach (string part in sbb.Parts)
                        {
                            MessagePart mp = msg.FindPartByName(part);
                            portParts.Remove(mp);
                            if (!mp.DefinedByType)
                            {
                                ctx.ReportRuleViolation(value, BasicProfileRules.R2203);
                            }
                        }
                    }
                }
            }

            SoapHeaderBinding shb = (SoapHeaderBinding)value.Extensions.Find(typeof(SoapHeaderBinding));

            if (shb != null)
            {
                Message     hm = ctx.Services.GetMessage(shb.Message);
                MessagePart mp = hm.FindPartByName(shb.Part);
                portParts.Remove(mp);
                if (mp != null && !mp.DefinedByElement)
                {
                    ctx.ReportRuleViolation(value, BasicProfileRules.R2205);
                }
            }

            SoapHeaderFaultBinding shfb = (SoapHeaderFaultBinding)value.Extensions.Find(typeof(SoapHeaderFaultBinding));

            if (shfb != null)
            {
                Message     hm = ctx.Services.GetMessage(shfb.Message);
                MessagePart mp = hm.FindPartByName(shfb.Part);
                portParts.Remove(mp);
                if (mp != null && !mp.DefinedByElement)
                {
                    ctx.ReportRuleViolation(value, BasicProfileRules.R2205);
                }
            }

            // TODO: SoapFaultBinding ??
        }
 private void Write107_SoapHeaderFaultBinding(string n, string ns, SoapHeaderFaultBinding o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(SoapHeaderFaultBinding)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("SoapHeaderFaultBinding", "http://schemas.xmlsoap.org/wsdl/soap12/");
         }
         if (o.Required)
         {
             base.WriteAttribute("required", "http://schemas.xmlsoap.org/wsdl/", XmlConvert.ToString(o.Required));
         }
         base.WriteAttribute("message", "", base.FromXmlQualifiedName(o.Message));
         base.WriteAttribute("part", "", o.Part);
         if (o.Use != SoapBindingUse.Default)
         {
             base.WriteAttribute("use", "", this.Write100_SoapBindingUse(o.Use));
         }
         if ((o.Encoding != null) && (o.Encoding.Length != 0))
         {
             base.WriteAttribute("encodingStyle", "", o.Encoding);
         }
         if ((o.Namespace != null) && (o.Namespace.Length != 0))
         {
             base.WriteAttribute("namespace", "", o.Namespace);
         }
         base.WriteEndElement(o);
     }
 }