internal static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.MessageBinding wsdlMessageBinding)
        {
            EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);

            WsdlNS.SoapHeaderBinding soapHeaderBinding = CreateSoapHeaderBinding(version, wsdlMessageBinding);
            return(soapHeaderBinding);
        }
            static WsdlNS.SoapHeaderBinding ConvertSoapHeaderBinding(WsdlNS.SoapHeaderBinding src, EnvelopeVersion version)
            {
                if (version == EnvelopeVersion.None)
                {
                    return(null);
                }

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

                WsdlNS.SoapHeaderBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12HeaderBinding() : new WsdlNS.SoapHeaderBinding();
                if (src != null)
                {
                    dest.Fault         = src.Fault;
                    dest.MapToProperty = src.MapToProperty;
                    dest.Message       = src.Message;
                    dest.Part          = src.Part;
                    dest.Encoding      = src.Encoding;
                    dest.Namespace     = src.Namespace;
                    dest.Use           = src.Use;
                    dest.Required      = src.Required;
                }
                return(dest);
            }
Beispiel #3
0
        protected virtual SoapHeaderBinding CreateSoapHeaderBinding(XmlQualifiedName message, string partName, SoapBindingUse use)
        {
            SoapHeaderBinding soapHeaderBinding = new SoapHeaderBinding();

            soapHeaderBinding.Message = message;
            soapHeaderBinding.Part    = partName;
            soapHeaderBinding.Use     = use;
            if (use == SoapBindingUse.Encoded)
            {
                soapHeaderBinding.Encoding = Soap.Encoding;
            }
            return(soapHeaderBinding);
        }
        protected virtual SoapHeaderBinding CreateSoapHeaderBinding(XmlQualifiedName message, string partName, string ns, SoapBindingUse use)
        {
            SoapHeaderBinding binding = new SoapHeaderBinding {
                Message = message,
                Part    = partName,
                Use     = use
            };

            if (use == SoapBindingUse.Encoded)
            {
                binding.Encoding  = "http://schemas.xmlsoap.org/soap/encoding/";
                binding.Namespace = ns;
            }
            return(binding);
        }
Beispiel #5
0
        bool HasHeader(MessageBinding msg, SoapHeaderBinding hb)
        {
            if (msg == null)
            {
                return(false);
            }

            foreach (object ob in msg.Extensions)
            {
                SoapHeaderBinding mhb = ob as SoapHeaderBinding;
                if ((mhb != null) && (mhb.Message == hb.Message) && (mhb.Part == hb.Part))
                {
                    return(true);
                }
            }
            return(false);
        }
        static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(EnvelopeVersion version, WsdlNS.MessageBinding wsdlMessageBinding)
        {
            WsdlNS.SoapHeaderBinding soapHeaderBinding = null;

            if (version == EnvelopeVersion.Soap12)
            {
                soapHeaderBinding = new WsdlNS.Soap12HeaderBinding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                soapHeaderBinding = new WsdlNS.SoapHeaderBinding();
            }
            Fx.Assert(soapHeaderBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");

            wsdlMessageBinding.Extensions.Add(soapHeaderBinding);
            return(soapHeaderBinding);
        }
 internal static bool Check(SoapHeaderBinding soapHeaderBinding, MessageBinding messageBinding, WsdlWarningHandler warningHandler)
 {
     if ((soapHeaderBinding.Message == null) || soapHeaderBinding.Message.IsEmpty)
     {
         string str = System.ServiceModel.SR.GetString("XsdMissingRequiredAttribute1", new object[] { "message" });
         string warning = System.ServiceModel.SR.GetString("IgnoreSoapHeaderBinding3", new object[] { messageBinding.OperationBinding.Name, messageBinding.OperationBinding.Binding.ServiceDescription.TargetNamespace, str });
         warningHandler(warning);
         return false;
     }
     if (string.IsNullOrEmpty(soapHeaderBinding.Part))
     {
         string str3 = System.ServiceModel.SR.GetString("XsdMissingRequiredAttribute1", new object[] { "part" });
         string str4 = System.ServiceModel.SR.GetString("IgnoreSoapHeaderBinding3", new object[] { messageBinding.OperationBinding.Name, messageBinding.OperationBinding.Binding.ServiceDescription.TargetNamespace, str3 });
         warningHandler(str4);
         return false;
     }
     return true;
 }
        public override void ReflectMethod()
        {
            SoapMethodStubInfo method = (SoapMethodStubInfo)ReflectionContext.MethodStubInfo;

            SoapOperationBinding sob = CreateSoapOperationBinding();

            sob.SoapAction = method.Action;
            sob.Style      = method.SoapBindingStyle;
            ReflectionContext.OperationBinding.Extensions.Add(sob);

            AddOperationMsgBindings(method, ReflectionContext.OperationBinding.Input);
            AddOperationMsgBindings(method, ReflectionContext.OperationBinding.Output);

            foreach (SoapHeaderMapping hf in method.Headers)
            {
                if (hf.Custom)
                {
                    continue;
                }

                SoapHeaderBinding hb = CreateSoapHeaderBinding();
                hb.Message = new XmlQualifiedName(ReflectionContext.Operation.Name + hf.HeaderType.Name, ReflectionContext.ServiceDescription.TargetNamespace);
                hb.Part    = hf.HeaderType.Name;
                hb.Use     = method.Use;

                if (method.Use != SoapBindingUse.Literal)
                {
                    hb.Encoding = EncodingNS;
                }

                if ((hf.Direction & SoapHeaderDirection.Out) != 0)
                {
                    ReflectionContext.OperationBinding.Output.Extensions.Add(hb);
                }
                if ((hf.Direction & SoapHeaderDirection.In) != 0)
                {
                    ReflectionContext.OperationBinding.Input.Extensions.Add(hb);
                }
            }
        }
Beispiel #9
0
        void ImportHeaders(CodeMemberMethod method)
        {
            foreach (object ob in OperationBinding.Input.Extensions)
            {
                SoapHeaderBinding hb = ob as SoapHeaderBinding;
                if (hb == null)
                {
                    continue;
                }
                if (HasHeader(OperationBinding.Output, hb))
                {
                    ImportHeader(method, hb, SoapHeaderDirection.In | SoapHeaderDirection.Out);
                }
                else
                {
                    ImportHeader(method, hb, SoapHeaderDirection.In);
                }
            }

            if (OperationBinding.Output == null)
            {
                return;
            }

            foreach (object ob in OperationBinding.Output.Extensions)
            {
                SoapHeaderBinding hb = ob as SoapHeaderBinding;
                if (hb == null)
                {
                    continue;
                }
                if (!HasHeader(OperationBinding.Input, hb))
                {
                    ImportHeader(method, hb, SoapHeaderDirection.Out);
                }
            }
        }
            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
            }
		void ImportHeader (CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction)
		{
			Message msg = ServiceDescriptions.GetMessage (hb.Message);
			if (msg == null) throw new InvalidOperationException ("Message " + hb.Message + " not found");
			MessagePart part = msg.Parts [hb.Part];
			if (part == null) throw new InvalidOperationException ("Message part " + hb.Part + " not found in message " + hb.Message);

			XmlTypeMapping map;
			if (hb.Use == SoapBindingUse.Literal)
			{
				map = xmlImporter.ImportDerivedTypeMapping (part.Element, typeof (SoapHeader));
				xmlExporter.ExportTypeMapping (map);
			}
			else
			{
				map = soapImporter.ImportDerivedTypeMapping (part.Type, typeof (SoapHeader), true);
				soapExporter.ExportTypeMapping (map);
			}

			bool required = false;

			string varName = headerVariables [map] as string;
			if (varName == null) 
			{
				varName = memberIds.AddUnique(CodeIdentifier.MakeValid (map.TypeName + "Value"),hb);
				headerVariables.Add (map, varName);
				CodeMemberField codeField = new CodeMemberField (map.TypeFullName, varName);
				codeField.Attributes = MemberAttributes.Public;
				CodeTypeDeclaration.Members.Add (codeField);
			}
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapHeaderAttribute");
			att.Arguments.Add (GetArg (varName));
			att.Arguments.Add (GetArg ("Required", required));
			if (direction != SoapHeaderDirection.In) att.Arguments.Add (GetEnumArg ("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString ()));
			AddCustomAttribute (method, att, true);
		}
		bool HasHeader (MessageBinding msg, SoapHeaderBinding hb)
		{
			if (msg == null) return false;
			
			foreach (object ob in msg.Extensions) 
			{
				SoapHeaderBinding mhb = ob as SoapHeaderBinding;
				if ((mhb != null) && (mhb.Message == hb.Message) && (mhb.Part == hb.Part)) 
					return true;
			}
			return false;
		}
        /// <summary>
        /// Exports the message header binding.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="messageBinding">The message binding.</param>
        /// <param name="qsName">Name of the qs.</param>
        /// <param name="isEncoded">if set to <c>true</c> [is encoded].</param>
        private void ExportMessageHeaderBinding(CustomHeaderExportInfo info, 
            MessageBinding messageBinding, XmlQualifiedName qsName)
        {
            ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "ExportMessageHeaderBinding");

            try
            {
                SoapHeaderBinding binding = new SoapHeaderBinding();
                binding.Part = info.PartName;
                binding.Message = qsName;
                binding.Use = (info.IsEncoded ? SoapBindingUse.Encoded : SoapBindingUse.Literal);

                messageBinding.Extensions.Add(binding);
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
Beispiel #14
0
		void ImportHeader (CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction)
		{
			Message msg = ServiceDescriptions.GetMessage (hb.Message);
			if (msg == null) throw new InvalidOperationException ("Message " + hb.Message + " not found");
			MessagePart part = msg.Parts [hb.Part];
			if (part == null) throw new InvalidOperationException ("Message part " + hb.Part + " not found in message " + hb.Message);

			XmlTypeMapping map;
			string hname;
			if (hb.Use == SoapBindingUse.Literal)
			{
				map = xmlImporter.ImportDerivedTypeMapping (part.Element, typeof (SoapHeader));
				hname = part.Element.Name;
				xmlExporter.ExportTypeMapping (map);
			}
			else
			{
				map = soapImporter.ImportDerivedTypeMapping (part.Type, typeof (SoapHeader), true);
				hname = part.Type.Name;
				soapExporter.ExportTypeMapping (map);
			}

			string varName = headerVariables [map] as string;
			if (varName == null) 
			{
				if (hname == map.TypeName)
					varName = memberIds.AddUnique(CodeIdentifier.MakeValid (hname + "Value"),hb);
				else
					varName = memberIds.AddUnique(CodeIdentifier.MakeValid (hname),hb);
				
				string propName = varName;
				varName = varName + "Field";
				headerVariables.Add (map, varName);
				CodeMemberField codeField = new CodeMemberField (map.TypeFullName, varName);
				CodeTypeDeclaration.Members.Add (codeField);
				
				codeField.Attributes = MemberAttributes.Private;
				CodeMemberProperty codeProperty = new CodeMemberProperty ();
				codeProperty.Name = propName;
				codeProperty.Type = new CodeTypeReference (map.TypeFullName);
				codeProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;
				codeProperty.HasGet = codeProperty.HasSet = true;
				CodeExpression ce = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), varName);
				codeProperty.SetStatements.Add (new CodeAssignStatement (ce, new CodePropertySetValueReferenceExpression()));
				codeProperty.GetStatements.Add (new CodeMethodReturnStatement (ce));
				CodeTypeDeclaration.Members.Add (codeProperty);

				varName = propName;
			}
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapHeaderAttribute");
			att.Arguments.Add (GetArg (varName));
#if ONLY_1_0
			att.Arguments.Add (GetArg ("Required", false));
#endif
			if (direction != SoapHeaderDirection.In) att.Arguments.Add (GetEnumArg ("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString ()));
			AddCustomAttribute (method, att, true);
		}
 protected virtual SoapHeaderBinding CreateSoapHeaderBinding(XmlQualifiedName message, string partName, string ns, SoapBindingUse use)
 {
     SoapHeaderBinding binding = new SoapHeaderBinding {
         Message = message,
         Part = partName,
         Use = use
     };
     if (use == SoapBindingUse.Encoded)
     {
         binding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/";
         binding.Namespace = ns;
     }
     return binding;
 }
        private static object GetSoapHeaderBinding(System.ServiceModel.Channels.Binding binding, string message, string ns)
        {
            if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap11)
            {
                SoapHeaderBinding headerBinding = new SoapHeaderBinding();
                headerBinding.Use = SoapBindingUse.Literal;
                headerBinding.Message = new XmlQualifiedName(message, ns);
                headerBinding.Part = Constants.DefaultMessagePartName;
                return headerBinding;
            }
            else if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap12)
            {
                Soap12HeaderBinding headerBinding = new Soap12HeaderBinding();
                headerBinding.Use = SoapBindingUse.Literal;
                headerBinding.Message = new XmlQualifiedName(message, ns);
                headerBinding.Part = Constants.DefaultMessagePartName;
                return headerBinding;
            }

            return null;
        }
        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);
            }
        }
Beispiel #18
0
        void WriteHeader(XmlTextWriter xtw, SoapHeaderBinding header)
        {
            Message msg = descriptions.GetMessage(header.Message);
            if (msg == null) throw new InvalidOperationException("Message " + header.Message + " not found");
            MessagePart part = msg.Parts[header.Part];
            if (part == null) throw new InvalidOperationException("Message part " + header.Part + " not found in message " + header.Message);

            currentUse = header.Use;

            if (currentUse == SoapBindingUse.Literal)
                WriteRootElementSample(xtw, part.Element);
            else
                WriteTypeSample(xtw, part.Type);
        }
 private void Write106_SoapHeaderBinding(string n, string ns, SoapHeaderBinding o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(SoapHeaderBinding)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("SoapHeaderBinding", "http://schemas.xmlsoap.org/wsdl/soap/");
         }
         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.Write98_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);
         }
         this.Write105_SoapHeaderFaultBinding("headerfault", "http://schemas.xmlsoap.org/wsdl/soap/", o.Fault, false, false);
         base.WriteEndElement(o);
     }
 }
Beispiel #20
0
        private static SoapBodyBinding FindSoapBodyBinding(bool input, ServiceDescriptionFormatExtensionCollection extensions, BasicProfileViolationCollection violations, bool documentBinding, string operationName, string bindingName, string bindingNs)
        {
            SoapBodyBinding binding = null;

            for (int i = 0; i < extensions.Count; i++)
            {
                object item      = extensions[i];
                string uriString = null;
                bool   flag      = false;
                bool   flag2     = false;
                if (item is SoapBodyBinding)
                {
                    flag      = true;
                    binding   = (SoapBodyBinding)item;
                    uriString = binding.Namespace;
                    flag2     = binding.Use == SoapBindingUse.Encoded;
                }
                else if (item is SoapHeaderBinding)
                {
                    flag = true;
                    SoapHeaderBinding binding2 = (SoapHeaderBinding)item;
                    uriString = binding2.Namespace;
                    flag2     = binding2.Use == SoapBindingUse.Encoded;
                    if (!flag2 && ((binding2.Part == null) || (binding2.Part.Length == 0)))
                    {
                        violations.Add("R2720", MessageString(binding2, operationName, bindingName, bindingNs, input, null));
                    }
                    if (binding2.Fault != null)
                    {
                        flag2 |= binding2.Fault.Use == SoapBindingUse.Encoded;
                        if (!flag2)
                        {
                            if ((binding2.Fault.Part == null) || (binding2.Fault.Part.Length == 0))
                            {
                                violations.Add("R2720", MessageString(binding2.Fault, operationName, bindingName, bindingNs, input, null));
                            }
                            if ((binding2.Fault.Namespace != null) && (binding2.Fault.Namespace.Length > 0))
                            {
                                violations.Add(documentBinding ? "R2716" : "R2726", MessageString(item, operationName, bindingName, bindingNs, input, null));
                            }
                        }
                    }
                }
                if (flag2)
                {
                    violations.Add("R2706", MessageString(item, operationName, bindingName, bindingNs, input, null));
                }
                else if (flag)
                {
                    if ((uriString == null) || (uriString.Length == 0))
                    {
                        if (!documentBinding && (item is SoapBodyBinding))
                        {
                            violations.Add("R2717", MessageString(item, operationName, bindingName, bindingNs, input, null));
                        }
                    }
                    else if (documentBinding || !(item is SoapBodyBinding))
                    {
                        violations.Add(documentBinding ? "R2716" : "R2726", MessageString(item, operationName, bindingName, bindingNs, input, null));
                    }
                    else
                    {
                        Uri uri;
                        if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri))
                        {
                            violations.Add("R2717", MessageString(item, operationName, bindingName, bindingNs, input, System.Web.Services.Res.GetString("UriValueRelative", new object[] { uriString })));
                        }
                    }
                }
            }
            return(binding);
        }
 protected virtual SoapHeaderBinding CreateSoapHeaderBinding(XmlQualifiedName message, string partName, string ns, SoapBindingUse use) {
     SoapHeaderBinding soapHeaderBinding = new SoapHeaderBinding();
     soapHeaderBinding.Message = message;
     soapHeaderBinding.Part = partName;
     soapHeaderBinding.Use = use;
     if (use == SoapBindingUse.Encoded) {
         soapHeaderBinding.Encoding = Soap.Encoding;
         soapHeaderBinding.Namespace = ns;
     }
     return soapHeaderBinding;
 }
Beispiel #22
0
        private void FindUse(Operation operation, ServiceDescription description, string messageName, ref bool isEncoded, ref bool isLiteral)
        {
            string targetNamespace = description.TargetNamespace;

            foreach (Binding binding in description.Bindings)
            {
                if (operation != null && !new XmlQualifiedName(operation.PortType.Name, targetNamespace).Equals(binding.Type))
                {
                    continue;
                }
                foreach (OperationBinding bindingOperation in binding.Operations)
                {
                    if (bindingOperation.Input != null)
                    {
                        foreach (object extension in bindingOperation.Input.Extensions)
                        {
                            if (operation != null)
                            {
                                SoapBodyBinding body = extension as SoapBodyBinding;
                                if (body != null && operation.IsBoundBy(bindingOperation))
                                {
                                    if (body.Use == SoapBindingUse.Encoded)
                                    {
                                        isEncoded = true;
                                    }
                                    else if (body.Use == SoapBindingUse.Literal)
                                    {
                                        isLiteral = true;
                                    }
                                }
                            }
                            else
                            {
                                SoapHeaderBinding header = extension as SoapHeaderBinding;
                                if (header != null && header.Message.Name == messageName)
                                {
                                    if (header.Use == SoapBindingUse.Encoded)
                                    {
                                        isEncoded = true;
                                    }
                                    else if (header.Use == SoapBindingUse.Literal)
                                    {
                                        isLiteral = true;
                                    }
                                }
                            }
                        }
                    }
                    if (bindingOperation.Output != null)
                    {
                        foreach (object extension in bindingOperation.Output.Extensions)
                        {
                            if (operation != null)
                            {
                                if (operation.IsBoundBy(bindingOperation))
                                {
                                    SoapBodyBinding body = extension as SoapBodyBinding;
                                    if (body != null)
                                    {
                                        if (body.Use == SoapBindingUse.Encoded)
                                        {
                                            isEncoded = true;
                                        }
                                        else if (body.Use == SoapBindingUse.Literal)
                                        {
                                            isLiteral = true;
                                        }
                                    }
                                    else if (extension is MimeXmlBinding)
                                    {
                                        isLiteral = true;
                                    }
                                }
                            }
                            else
                            {
                                SoapHeaderBinding header = extension as SoapHeaderBinding;
                                if (header != null && header.Message.Name == messageName)
                                {
                                    if (header.Use == SoapBindingUse.Encoded)
                                    {
                                        isEncoded = true;
                                    }
                                    else if (header.Use == SoapBindingUse.Literal)
                                    {
                                        isLiteral = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #23
0
        private void FindUse(Operation operation, ServiceDescription description, string messageName, ref bool isEncoded, ref bool isLiteral)
        {
            string targetNamespace = description.TargetNamespace;

            foreach (Binding binding in description.Bindings)
            {
                if ((operation == null) || new XmlQualifiedName(operation.PortType.Name, targetNamespace).Equals(binding.Type))
                {
                    foreach (OperationBinding binding2 in binding.Operations)
                    {
                        if (binding2.Input != null)
                        {
                            foreach (object obj2 in binding2.Input.Extensions)
                            {
                                if (operation != null)
                                {
                                    SoapBodyBinding binding3 = obj2 as SoapBodyBinding;
                                    if ((binding3 != null) && operation.IsBoundBy(binding2))
                                    {
                                        if (binding3.Use == SoapBindingUse.Encoded)
                                        {
                                            isEncoded = true;
                                        }
                                        else if (binding3.Use == SoapBindingUse.Literal)
                                        {
                                            isLiteral = true;
                                        }
                                    }
                                }
                                else
                                {
                                    SoapHeaderBinding binding4 = obj2 as SoapHeaderBinding;
                                    if ((binding4 != null) && (binding4.Message.Name == messageName))
                                    {
                                        if (binding4.Use == SoapBindingUse.Encoded)
                                        {
                                            isEncoded = true;
                                        }
                                        else if (binding4.Use == SoapBindingUse.Literal)
                                        {
                                            isLiteral = true;
                                        }
                                    }
                                }
                            }
                        }
                        if (binding2.Output != null)
                        {
                            foreach (object obj3 in binding2.Output.Extensions)
                            {
                                if (operation != null)
                                {
                                    if (operation.IsBoundBy(binding2))
                                    {
                                        SoapBodyBinding binding5 = obj3 as SoapBodyBinding;
                                        if (binding5 != null)
                                        {
                                            if (binding5.Use == SoapBindingUse.Encoded)
                                            {
                                                isEncoded = true;
                                            }
                                            else if (binding5.Use == SoapBindingUse.Literal)
                                            {
                                                isLiteral = true;
                                            }
                                        }
                                        else if (obj3 is MimeXmlBinding)
                                        {
                                            isLiteral = true;
                                        }
                                    }
                                }
                                else
                                {
                                    SoapHeaderBinding binding6 = obj3 as SoapHeaderBinding;
                                    if ((binding6 != null) && (binding6.Message.Name == messageName))
                                    {
                                        if (binding6.Use == SoapBindingUse.Encoded)
                                        {
                                            isEncoded = true;
                                        }
                                        else if (binding6.Use == SoapBindingUse.Literal)
                                        {
                                            isLiteral = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        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 ??
        }
Beispiel #26
0
        void ImportHeader(CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction)
        {
            Message msg = ServiceDescriptions.GetMessage(hb.Message);

            if (msg == null)
            {
                throw new InvalidOperationException("Message " + hb.Message + " not found");
            }
            MessagePart part = msg.Parts [hb.Part];

            if (part == null)
            {
                throw new InvalidOperationException("Message part " + hb.Part + " not found in message " + hb.Message);
            }

            XmlTypeMapping map;
            string         hname;

            if (hb.Use == SoapBindingUse.Literal)
            {
                map   = xmlImporter.ImportDerivedTypeMapping(part.Element, typeof(SoapHeader));
                hname = part.Element.Name;
                xmlExporter.ExportTypeMapping(map);
            }
            else
            {
                map   = soapImporter.ImportDerivedTypeMapping(part.Type, typeof(SoapHeader), true);
                hname = part.Type.Name;
                soapExporter.ExportTypeMapping(map);
            }

            string varName = headerVariables [map] as string;

            if (varName == null)
            {
                if (hname == map.TypeName)
                {
                    varName = memberIds.AddUnique(CodeIdentifier.MakeValid(hname + "Value"), hb);
                }
                else
                {
                    varName = memberIds.AddUnique(CodeIdentifier.MakeValid(hname), hb);
                }

#if NET_2_0
                string propName = varName;
                varName = varName + "Field";
#endif
                headerVariables.Add(map, varName);
                CodeMemberField codeField = new CodeMemberField(map.TypeFullName, varName);
                CodeTypeDeclaration.Members.Add(codeField);

#if NET_2_0
                codeField.Attributes = MemberAttributes.Private;
                CodeMemberProperty codeProperty = new CodeMemberProperty();
                codeProperty.Name       = propName;
                codeProperty.Type       = new CodeTypeReference(map.TypeFullName);
                codeProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                codeProperty.HasGet     = codeProperty.HasSet = true;
                CodeExpression ce = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), varName);
                codeProperty.SetStatements.Add(new CodeAssignStatement(ce, new CodePropertySetValueReferenceExpression()));
                codeProperty.GetStatements.Add(new CodeMethodReturnStatement(ce));
                CodeTypeDeclaration.Members.Add(codeProperty);

                varName = propName;
#else
                codeField.Attributes = MemberAttributes.Public;
#endif
            }

            CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Web.Services.Protocols.SoapHeaderAttribute");
            att.Arguments.Add(GetArg(varName));
#if ONLY_1_0
            att.Arguments.Add(GetArg("Required", false));
#endif
            if (direction != SoapHeaderDirection.In)
            {
                att.Arguments.Add(GetEnumArg("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString()));
            }
            AddCustomAttribute(method, att, true);
        }
		protected override bool ReflectMethod ()
		{
			SoapOperationBinding sob = new SoapOperationBinding();
			SoapMethodStubInfo method = (SoapMethodStubInfo) MethodStubInfo;
			
			sob.SoapAction = method.Action;
			sob.Style = method.SoapBindingStyle;
			OperationBinding.Extensions.Add (sob);
			
			ImportMessage (method.InputMembersMapping, InputMessage);
			ImportMessage (method.OutputMembersMapping, OutputMessage);
				
			AddOperationMsgBindings (method, OperationBinding.Input);
			AddOperationMsgBindings (method, OperationBinding.Output);

			foreach (HeaderInfo hf in method.Headers)
			{
				if (hf.IsUnknownHeader) continue;
				
				Message msg = new Message ();
				msg.Name = Operation.Name + hf.HeaderType.Name;
				MessagePart part = new MessagePart ();
				part.Name = hf.HeaderType.Name;
				msg.Parts.Add (part);
				ServiceDescription.Messages.Add (msg);

				SoapHeaderBinding hb = new SoapHeaderBinding ();
				hb.Message = new XmlQualifiedName (msg.Name, ServiceDescription.TargetNamespace);
				hb.Part = part.Name;
				hb.Use = method.Use;
				
				if (method.Use == SoapBindingUse.Literal)
				{
					// MS.NET reflects header classes in a weird way. The root element
					// name is the CLR class name unless it is specified in an XmlRootAttribute.
					// The usual is to use the xml type name by default, but not in this case.
				
					XmlRootAttribute root;
					XmlAttributes ats = new XmlAttributes (hf.HeaderType);
					if (ats.XmlRoot != null) root = ats.XmlRoot;
					else root = new XmlRootAttribute (hf.HeaderType.Name);
					
					if (root.Namespace == null) root.Namespace = TypeInfo.LogicalType.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace);
					if (root.ElementName == null) root.ElementName = hf.HeaderType.Name;
					
					XmlTypeMapping mapping = ReflectionImporter.ImportTypeMapping (hf.HeaderType, root);
					part.Element = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
					SchemaExporter.ExportTypeMapping (mapping);
				}
				else
				{
					XmlTypeMapping mapping = SoapReflectionImporter.ImportTypeMapping (hf.HeaderType, TypeInfo.LogicalType.GetWebServiceEncodedNamespace (ServiceDescription.TargetNamespace));
					part.Type = new XmlQualifiedName (mapping.ElementName, mapping.Namespace);
					SoapSchemaExporter.ExportTypeMapping (mapping);
					hb.Encoding = EncodingNamespace;
				}

				if ((hf.Direction & SoapHeaderDirection.Out) != 0)
					OperationBinding.Output.Extensions.Add (hb);
				if ((hf.Direction & SoapHeaderDirection.In) != 0)
					OperationBinding.Input.Extensions.Add (hb);
			}
			
			return true;
		}