public static void Main()
    {
// <Snippet1>
        // Read from an existing wsdl file.
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("MapToProperty_cs.wsdl");
        // Get the existing binding
        Binding          myBinding          = myServiceDescription.Bindings["MyWebServiceSoap"];
        OperationBinding myOperationBinding =
            (OperationBinding)myBinding.Operations[0];
        InputBinding myInputBinding = myOperationBinding.Input;
        // Get the 'SoapHeaderBinding' instance from 'myInputBinding'.
        SoapHeaderBinding mySoapHeaderBinding =
            (SoapHeaderBinding)myInputBinding.Extensions[1];

        if (mySoapHeaderBinding.MapToProperty)
        {
            Console.WriteLine("'SoapHeaderBinding' instance is mapped to a " +
                              "specific property in proxy generated class");
        }
        else
        {
            Console.WriteLine("'SoapHeaderBinding' instance is not mapped to " +
                              "a specific property in proxy generated class");
        }
// </Snippet1>
    }
示例#2
0
            private static SoapHeaderBinding ConvertSoapHeaderBinding(SoapHeaderBinding src, EnvelopeVersion version)
            {
                if (version == EnvelopeVersion.None)
                {
                    return(null);
                }
                if (GetBindingVersion <Soap12HeaderBinding>(src) == version)
                {
                    return(src);
                }
                SoapHeaderBinding binding = (version == EnvelopeVersion.Soap12) ? new Soap12HeaderBinding() : new SoapHeaderBinding();

                if (src != null)
                {
                    binding.Fault         = src.Fault;
                    binding.MapToProperty = src.MapToProperty;
                    binding.Message       = src.Message;
                    binding.Part          = src.Part;
                    binding.Encoding      = src.Encoding;
                    binding.Namespace     = src.Namespace;
                    binding.Use           = src.Use;
                    binding.Required      = src.Required;
                }
                return(binding);
            }
示例#3
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);
            }
        }
示例#4
0
            internal static bool ConvertSoapMessageBinding(ref object src, EnvelopeVersion version)
            {
                SoapBodyBinding binding = src as SoapBodyBinding;

                if (binding != null)
                {
                    src = ConvertSoapBodyBinding(binding, version);
                    return(true);
                }
                SoapHeaderBinding binding2 = src as SoapHeaderBinding;

                if (binding2 != null)
                {
                    src = ConvertSoapHeaderBinding(binding2, version);
                    return(true);
                }
                SoapFaultBinding binding3 = src as SoapFaultBinding;

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

                if ((element != null) && SoapHelper.IsSoapFaultBinding(element))
                {
                    src = ConvertSoapFaultBinding(element, version);
                    return(true);
                }
                return(src == null);
            }
示例#5
0
        public override XmlElement CreateSoapHeader(SoapHeaderBinding binding)
        {
            var element = document.CreateElement(PrefixConstants.SOAP, "header", NamespaceConstants.SOAP);

            element.SetAttribute("message", $"{PrefixConstants.TARGET}:{binding.Message.Name}");
            element.SetAttribute("part", binding.Part);
            element.SetAttribute("use", "literal");

            return(element);
        }
示例#6
0
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("SoapHeaderBindingInput_cs.wsdl");
        Binding myBinding = new Binding();

        myBinding.Name = "MyWebServiceSoap";
        myBinding.Type = new XmlQualifiedName("s0:MyWebServiceSoap");

        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        mySoapBinding.Style     = SoapBindingStyle.Document;
        myBinding.Extensions.Add(mySoapBinding);

        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "Hello";

        SoapOperationBinding mySoapOperationBinding =
            new SoapOperationBinding();

        mySoapOperationBinding.SoapAction = "http://tempuri.org/Hello";
        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        myOperationBinding.Extensions.Add(mySoapOperationBinding);

        // Create InputBinding for operation for the 'SOAP' protocol.
        InputBinding    myInputBinding    = new InputBinding();
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use = SoapBindingUse.Literal;
        myInputBinding.Extensions.Add(mySoapBodyBinding);
        SoapHeaderBinding mySoapHeaderBinding = new SoapHeaderBinding();

        mySoapHeaderBinding.Message = new XmlQualifiedName("s0:HelloMyHeader");
        mySoapHeaderBinding.Part    = "MyHeader";
        mySoapHeaderBinding.Use     = SoapBindingUse.Literal;
        // Add mySoapHeaderBinding to 'myInputBinding' object.
        myInputBinding.Extensions.Add(mySoapHeaderBinding);
        // Create OutputBinding for operation for the 'SOAP' protocol.
        OutputBinding myOutputBinding = new OutputBinding();

        myOutputBinding.Extensions.Add(mySoapBodyBinding);

        // Add 'InputBinding' and 'OutputBinding' to 'OperationBinding'.
        myOperationBinding.Input  = myInputBinding;
        myOperationBinding.Output = myOutputBinding;
        myBinding.Operations.Add(myOperationBinding);

        myServiceDescription.Bindings.Add(myBinding);
        myServiceDescription.Write("SoapHeaderBindingOut_cs.wsdl");
        Console.WriteLine("'SoapHeaderBindingOut_cs.wsdl' file is generated.");
        Console.WriteLine("Proxy could be created using "
                          + "'wsdl SoapHeaderBindingOut_cs.wsdl'.");
    }
示例#7
0
        public override XmlElement CreateSoapHeader(SoapHeaderBinding binding)
        {
            var element = document.CreateElement(PrefixConstants.SOAP, "header", NamespaceConstants.SOAP);

            element.SetAttribute("message", binding.Message.Name);
            element.SetAttribute("part", binding.Part);
            element.SetAttribute("use", "encoded");
            element.SetAttribute("namespace", binding.Namespace);
            element.SetAttribute("encodingStyle", binding.Encoding);

            return(element);
        }
示例#8
0
            private void ExportMessageHeaderBinding(MessageHeaderDescription header, XmlQualifiedName messageName, bool isEncoded, MessageBinding messageBinding)
            {
                SoapHeaderBinding binding = SoapHelper.CreateSoapHeaderBinding(this.endpointContext, messageBinding);

                binding.Part    = string.IsNullOrEmpty(header.UniquePartName) ? header.Name : header.UniquePartName;
                binding.Message = messageName;
                binding.Use     = isEncoded ? SoapBindingUse.Encoded : SoapBindingUse.Literal;
                if (isEncoded)
                {
                    binding.Encoding = XmlSerializerOperationFormatter.GetEncoding(this.soapVersion);
                }
            }
示例#9
0
        private static SoapHeaderBinding CreateSoapHeaderBinding(EnvelopeVersion version, MessageBinding wsdlMessageBinding)
        {
            SoapHeaderBinding extension = null;

            if (version == EnvelopeVersion.Soap12)
            {
                extension = new Soap12HeaderBinding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                extension = new SoapHeaderBinding();
            }
            wsdlMessageBinding.Extensions.Add(extension);
            return(extension);
        }
 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);
 }
        /// <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);
            }
        }
示例#12
0
        public static SoapHeaderBinding CreateHeaderBinding(Message msg, string partName, bool required)
        {
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            SoapHeaderBinding ret = new SoapHeaderBinding();

            if ((partName == null) && (msg.Parts.Count > 0))
            {
                partName = msg.Parts[0].Name;
            }
            ret.Part     = partName;
            ret.Message  = new XmlQualifiedName(msg.Name, (msg.ServiceDescription == null ? String.Empty : msg.ServiceDescription.TargetNamespace));
            ret.Use      = SoapBindingUse.Literal;
            ret.Required = required;

            return(ret);
        }
        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);
        }
示例#14
0
        public string GenerateSoapMessage(OperationBinding obin, Operation oper, OperationMessage msg)
        {
            SoapOperationBinding sob   = obin.Extensions.Find(typeof(SoapOperationBinding)) as SoapOperationBinding;
            SoapBindingStyle     style = (sob != null) ? sob.Style : SoapBindingStyle.Document;

            MessageBinding  msgbin  = (msg is OperationInput) ? (MessageBinding)obin.Input : (MessageBinding)obin.Output;
            SoapBodyBinding sbb     = msgbin.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding;
            SoapBindingUse  bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;

            StringWriter  sw  = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);

            xtw.Formatting = Formatting.Indented;

            xtw.WriteStartDocument();
            xtw.WriteStartElement("soap", "Envelope", SoapEnvelopeNamespace);
            xtw.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
            xtw.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace);

            if (bodyUse == SoapBindingUse.Encoded)
            {
                xtw.WriteAttributeString("xmlns", "soapenc", null, SoapEncodingNamespace);
                xtw.WriteAttributeString("xmlns", "tns", null, msg.Message.Namespace);
            }

            // Serialize headers

            bool writtenHeader = false;

            foreach (object ob in msgbin.Extensions)
            {
                SoapHeaderBinding hb = ob as SoapHeaderBinding;
                if (hb == null)
                {
                    continue;
                }

                if (!writtenHeader)
                {
                    xtw.WriteStartElement("soap", "Header", SoapEnvelopeNamespace);
                    writtenHeader = true;
                }

                WriteHeader(xtw, hb);
            }

            if (writtenHeader)
            {
                xtw.WriteEndElement();
            }

            // Serialize body
            xtw.WriteStartElement("soap", "Body", SoapEnvelopeNamespace);

            currentUse = bodyUse;
            WriteBody(xtw, oper, msg, sbb, style);

            xtw.WriteEndElement();
            xtw.WriteEndElement();
            xtw.Close();
            return(sw.ToString());
        }
示例#15
0
        public ServiceDescription exportWSDL(EA.Repository repository, EA.Element component)
        {
            string faultnamespace = "http://www.iag.co.nz/soa/iagiaa/fault";
            string iaaNamespace   = "http://www.iag.co.nz/soa/iagiaa/v2";

            string wsdlNamespace = component.Version;

            ServiceDescription service = new ServiceDescription();

            service.TargetNamespace = wsdlNamespace;
            service.Name            = component.Name;

            service.Namespaces.Add("iaa", iaaNamespace);
            service.Namespaces.Add("fault", faultnamespace);
            service.Namespaces.Add("soa", wsdlNamespace);

            XmlSchema schema = new XmlSchema();

            service.Documentation = component.Notes;
            {
                schema.ElementFormDefault = XmlSchemaForm.Qualified;
                schema.TargetNamespace    = component.Version;

                {
                    XmlSchemaImport si = new XmlSchemaImport();
                    si.SchemaLocation = "iagiaa_.xsd";
                    si.Namespace      = iaaNamespace;
                    schema.Includes.Add(si);
                }
                {
                    XmlSchemaImport si = new XmlSchemaImport();
                    si.SchemaLocation = "iagiaa_fault.xsd";
                    si.Namespace      = faultnamespace;
                    schema.Includes.Add(si);
                }
                service.Types.Schemas.Add(schema);
            }

            Message faultMessage = new Message();
            {
                faultMessage.Name = "ErrorInfo";
                service.Messages.Add(faultMessage);

                MessagePart mp = new MessagePart();
                mp.Name = "ErrorInfo";
                XmlQualifiedName qn = new XmlQualifiedName("ErrorInfo", faultnamespace);
                mp.Element = qn;
                faultMessage.Parts.Add(mp);
            }



            Binding binding = new Binding();

            service.Bindings.Add(binding);
            binding.Name = component.Name;
            binding.Type = new XmlQualifiedName(component.Name, wsdlNamespace);

            Soap12Binding soapBinding = new Soap12Binding();

            binding.Extensions.Add(soapBinding);
            soapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";

            PortType portType = new PortType();

            portType.Name = component.Name;
            service.PortTypes.Add(portType);

            foreach (EA.Method m in component.Methods)
            {
                {
                }

                {
                    Message inMessage = new Message();
                    inMessage.Name = m.Name + "SoapIn";
                    service.Messages.Add(inMessage);

                    MessagePart mp = new MessagePart();
                    mp.Name = "Header";
                    XmlQualifiedName qn = new XmlQualifiedName("ApplicationContext", iaaNamespace);
                    mp.Element = qn;
                    inMessage.Parts.Add(mp);

                    MessagePart ip = new MessagePart();
                    ip.Name = m.Name + "Part";
                    XmlQualifiedName iqn = new XmlQualifiedName(m.Name, wsdlNamespace);
                    ip.Element = iqn;
                    inMessage.Parts.Add(ip);
                }
                {
                    Message outMessage = new Message();
                    outMessage.Name = m.Name + "SoapOut";
                    service.Messages.Add(outMessage);

                    MessagePart ip = new MessagePart();
                    ip.Name = m.Name + "ResponsePart";
                    XmlQualifiedName iqn = new XmlQualifiedName(m.Name + "Response", wsdlNamespace);
                    ip.Element = iqn;
                    outMessage.Parts.Add(ip);
                }

                {
                    Operation operation = new Operation();
                    portType.Operations.Add(operation);
                    operation.Name = m.Name;

                    OperationInput oi = new OperationInput();
                    oi.Message = new XmlQualifiedName(component.Name + "SoapIn", component.Version);
                    operation.Messages.Add(oi);


                    OperationOutput oo = new OperationOutput();
                    oo.Message = new XmlQualifiedName(component.Name + "SoapOut", component.Version);
                    operation.Messages.Add(oo);

                    OperationFault of = new OperationFault();
                    of.Name    = faultMessage.Name;
                    of.Message = new XmlQualifiedName("ErrorInfo", component.Version);
                    operation.Faults.Add(of);
                }

                {
                    OperationBinding opBinding = new OperationBinding();
                    binding.Operations.Add(opBinding);
                    opBinding.Input  = new InputBinding();
                    opBinding.Output = new OutputBinding();
                    FaultBinding faultBinding = new FaultBinding();
                    opBinding.Faults.Add(faultBinding);

                    SoapHeaderBinding headerBinding = new SoapHeaderBinding();
                    opBinding.Input.Extensions.Add(headerBinding);
                    headerBinding.Message = new XmlQualifiedName(m.Name + "SoapIn", wsdlNamespace);
                    headerBinding.Part    = "Header";
                    headerBinding.Use     = SoapBindingUse.Literal;

                    SoapBodyBinding bodyBinding = new SoapBodyBinding();
                    opBinding.Input.Extensions.Add(bodyBinding);
                    bodyBinding.PartsString = m.Name + "Part";


                    SoapBodyBinding outBinding = new SoapBodyBinding();
                    opBinding.Output.Extensions.Add(outBinding);
                    outBinding.Use = SoapBindingUse.Literal;

                    faultBinding.Name = "ErrorResponseType";
                    SoapFaultBinding soapFaultBinding = new SoapFaultBinding();
                    faultBinding.Extensions.Add(soapFaultBinding);
                    soapFaultBinding.Use = SoapBindingUse.Literal;
                }
            }
            return(service);
        }
示例#16
0
 /// <summary>
 /// Create SOAP header element.
 /// </summary>
 public abstract XmlElement CreateSoapHeader(SoapHeaderBinding binding);
示例#17
0
        /// <summary>
        /// Validates a specified instance of <see cref="ServiceDescription"/> class for the round tripping feature.
        /// </summary>
        /// <param name="serviceDescription">
        /// An instance of <see cref="ServiceDescription"/> class to
        /// validate.
        /// </param>
        /// <param name="isHttpBinding">A reference to a Boolean variable. Value is this variable is set to true if the service description has Http binding.</param>
        /// <returns>
        /// A value indicating whether the specified instance of <see cref="ServiceDescription"/>
        /// class is valid for the round tripping feature.
        /// </returns>
        private static bool ValidateWsdl(
            System.Web.Services.Description.ServiceDescription serviceDescription,
            ref bool isHttpBinding)
        {
            // Rule No 1: Service description must have atleast one schema in the types definitions.
            if (serviceDescription.Types.Schemas.Count == 0)
            {
                return(false);
            }

            // Rule No 2: Service description must have only one <porttype>.
            if (serviceDescription.PortTypes.Count != 1)
            {
                return(false);
            }

            // Rule No 3: Service description must have only SOAP 1.1 and/or SOAP 1.2 binding(s).
            if (!((serviceDescription.Bindings.Count == 1 && serviceDescription.Bindings[0].Extensions.Find(typeof(SoapBinding)) != null) ||
                  (serviceDescription.Bindings.Count == 2 && serviceDescription.Bindings[0].Extensions.Find(typeof(SoapBinding)) != null &&
                   serviceDescription.Bindings[1].Extensions.Find(typeof(Soap12Binding)) != null)))
            {
                return(false);
            }

            // Rule No 4: Service description can not have more than one <service>. But it is possible
            // not to have a <service>.
            if (serviceDescription.Services.Count > 1)
            {
                return(false);
            }

            // Rule No 5: Each message must have only one <part>.
            foreach (FxMessage message in serviceDescription.Messages)
            {
                if (message.Parts.Count > 1)
                {
                    return(false);
                }
            }

            // Rule No 6: For soap bindings the binding style must be 'Document' and encoding must be 'Literal'.

            // Obtain a reference to the one and only binding we have.
            System.Web.Services.Description.Binding binding = serviceDescription.Bindings[0];

            // Search for the soap binding style and return false if it is not 'Document'
            foreach (ServiceDescriptionFormatExtension extension in binding.Extensions)
            {
                SoapBinding soapBinding = extension as SoapBinding;
                if (soapBinding != null)
                {
                    if (soapBinding.Style != SoapBindingStyle.Document)
                    {
                        return(false);
                    }
                }
                else if (extension is HttpBinding)
                {
                    isHttpBinding = true;
                }
            }

            // Validate the operation bindings.
            foreach (OperationBinding operationBinding in binding.Operations)
            {
                // Validate the soap binding style in soap operation binding extension.
                foreach (ServiceDescriptionFormatExtension extension in operationBinding.Extensions)
                {
                    SoapOperationBinding soapOperationBinding = extension as SoapOperationBinding;

                    if (soapOperationBinding != null)
                    {
                        if (soapOperationBinding.Style != SoapBindingStyle.Document)
                        {
                            return(false);
                        }
                    }
                }

                // Validate the 'use' element in input message body and the headers.
                foreach (ServiceDescriptionFormatExtension extension in operationBinding.Input.Extensions)
                {
                    // Check for a header.
                    SoapHeaderBinding headerBinding = extension as SoapHeaderBinding;
                    if (headerBinding != null)
                    {
                        if (headerBinding.Use != SoapBindingUse.Literal)
                        {
                            return(false);
                        }
                        continue;
                    }

                    // Check for the body.
                    SoapBodyBinding bodyBinding = extension as SoapBodyBinding;
                    if (bodyBinding != null)
                    {
                        if (bodyBinding.Use != SoapBindingUse.Literal)
                        {
                            return(false);
                        }

                        continue;
                    }
                }

                // Validate the 'use' element in output message body and the headers.
                if (operationBinding.Output != null)
                {
                    foreach (ServiceDescriptionFormatExtension extension in operationBinding.Output.Extensions)
                    {
                        // Check for the header.
                        SoapHeaderBinding headerBinding = extension as SoapHeaderBinding;
                        if (headerBinding != null)
                        {
                            if (headerBinding.Use != SoapBindingUse.Literal)
                            {
                                return(false);
                            }
                            continue;
                        }

                        // Check for the body.
                        SoapBodyBinding bodyBinding = extension as SoapBodyBinding;
                        if (bodyBinding != null)
                        {
                            if (bodyBinding.Use != SoapBindingUse.Literal)
                            {
                                return(false);
                            }

                            continue;
                        }
                    }
                }
            }

            return(true);
        }
示例#18
0
        /// <summary>
        /// Creates an <see cref="InterfaceContract"/> object by loading the contents in a specified
        /// WSDL file.
        /// </summary>
        /// <param name="wsdlFileName">Path of the WSDL file to load the information from.</param>
        /// <returns>An instance of <see cref="InterfaceContract"/> with the information loaded from the WSDL file.</returns>
        /// <remarks>
        /// This method first loads the content of the WSDL file to an instance of
        /// <see cref="System.Web.Services.Description.ServiceDescription"/> class. Then it creates an
        /// instance of <see cref="InterfaceContract"/> class by loading the data from that.
        /// This method throws <see cref="WsdlLoadException"/> in case of a failure to load the WSDL file.
        /// </remarks>
        public static InterfaceContract GetInterfaceContract(string wsdlFileName)
        {
            // Try to load the service description from the specified file.
            LoadWsdl(wsdlFileName);

            // Validate the WSDL before proceeding.
            CheckIfWsdlIsUsableForRoundtripping();

            // Start building the simplified InterfaceContract object from the
            // .Net Fx ServiceDescription we created.
            InterfaceContract simpleContract = new InterfaceContract();

            // Initialize the basic meta data.
            simpleContract.ServiceName          = srvDesc.Name;
            simpleContract.ServiceNamespace     = srvDesc.TargetNamespace;
            simpleContract.ServiceDocumentation = srvDesc.Documentation;
            // Try to get the service namespace from the service description.

            // If it was not found in the service description. Then try to get it from the
            // service. If it is not found their either, then try to get it from binding.
            if (simpleContract.ServiceName == null || simpleContract.ServiceName == "")
            {
                if (srvDesc.Services.Count > 0 && srvDesc.Services[0].Name != null &&
                    srvDesc.Services[0].Name != "")
                {
                    simpleContract.ServiceName = srvDesc.Services[0].Name;
                }
                else
                {
                    simpleContract.ServiceName = srvDesc.Bindings[0].Name;
                }
            }

            // Set the http binding property.
            simpleContract.IsHttpBinding = isHttpBinding;

            // Initialize the imports.
            foreach (XmlSchema typeSchema in srvDesc.Types.Schemas)
            {
                foreach (XmlSchemaObject schemaObject in typeSchema.Includes)
                {
                    XmlSchemaImport import = schemaObject as XmlSchemaImport;

                    if (import != null)
                    {
                        SchemaImport simpleImport = new SchemaImport();
                        simpleImport.SchemaNamespace = import.Namespace;
                        simpleImport.SchemaLocation  = import.SchemaLocation;
                        simpleContract.Imports.Add(simpleImport);
                    }
                }
            }

            // Initialize the types embedded to the WSDL.
            simpleContract.SetTypes(GetSchemaElements(srvDesc.Types.Schemas, srvDesc.TargetNamespace));

            // Initialize the operations and in/out messages.
            PortType ptype = srvDesc.PortTypes[0];

            if (ptype != null)
            {
                foreach (FxOperation op in ptype.Operations)
                {
                    // Create the Operation.
                    Operation simpleOp = new Operation();
                    simpleOp.Name          = op.Name;
                    simpleOp.Documentation = op.Documentation;

                    if (op.Messages.Input != null)
                    {
                        FxMessage inMessage = srvDesc.Messages[op.Messages.Input.Message.Name];

                        if (inMessage == null)
                        {
                            // WSDL modified.
                            throw new WsdlModifiedException("Could not find the message");
                        }

                        MessagePart part = inMessage.Parts[0];
                        if (part != null)
                        {
                            // Create the input message.
                            Message simpleInMessage = new Message();
                            simpleInMessage.Name = inMessage.Name;
                            simpleInMessage.Element.ElementName      = part.Element.Name;
                            simpleInMessage.Element.ElementNamespace = part.Element.Namespace;
                            simpleInMessage.Documentation            = inMessage.Documentation;

                            simpleOp.MessagesCollection.Add(simpleInMessage);

                            simpleOp.Input = simpleInMessage;
                        }
                        else
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message part");
                        }
                    }

                    if (op.Messages.Output != null)
                    {
                        FxMessage outMessage = srvDesc.Messages[op.Messages.Output.Message.Name];

                        if (outMessage == null)
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message");
                        }

                        MessagePart part = outMessage.Parts[0];
                        if (part != null)
                        {
                            // Create the output message.
                            Message simpleOutMessage = new Message();
                            simpleOutMessage.Name = outMessage.Name;
                            simpleOutMessage.Element.ElementName      = part.Element.Name;
                            simpleOutMessage.Element.ElementNamespace = part.Element.Namespace;
                            simpleOutMessage.Documentation            = outMessage.Documentation;

                            simpleOp.MessagesCollection.Add(simpleOutMessage);

                            simpleOp.Output = simpleOutMessage;
                        }
                        else
                        {
                            // WSDL is modified.
                            throw new WsdlModifiedException("Could not find the message part");
                        }

                        // Set the message direction.
                        simpleOp.Mep = Mep.RequestResponse;
                    }
                    else
                    {
                        simpleOp.Mep = Mep.OneWay;
                    }

                    // Finally add the Operation to Operations collection.
                    simpleContract.Operations.Add(simpleOp);
                }
            }
            else
            {
                // WSDL is modified.
                throw new WsdlModifiedException("Could not find the portType");
            }

            // Initialize the message headers and header messages.
            System.Web.Services.Description.Binding binding1 = srvDesc.Bindings[0];
            if (binding1 != null)
            {
                // Find the corresponding Operation in the InterfaceContract, for each OperationBinding
                // in the binding1.Operations collection.
                foreach (OperationBinding opBinding in binding1.Operations)
                {
                    foreach (Operation simpleOp in simpleContract.Operations)
                    {
                        if (simpleOp.Name == opBinding.Name)
                        {
                            if (opBinding.Input != null)
                            {
                                // Enumerate the message headers for the input message.
                                foreach (ServiceDescriptionFormatExtension extension in opBinding.Input.Extensions)
                                {
                                    SoapHeaderBinding inHeader = extension as SoapHeaderBinding;
                                    if (inHeader != null)
                                    {
                                        // Create the in header and add it to the headers collection.
                                        MessageHeader simpleInHeader  = new MessageHeader();
                                        FxMessage     inHeaderMessage = srvDesc.Messages[inHeader.Message.Name];

                                        if (inHeaderMessage == null)
                                        {
                                            // WSDL modified.
                                            throw new WsdlModifiedException("Could not find the message");
                                        }

                                        simpleInHeader.Name    = inHeaderMessage.Name;
                                        simpleInHeader.Message = inHeaderMessage.Name;
                                        simpleOp.MessagesCollection[0].HeadersCollection.Add(simpleInHeader);

                                        // Create the in header message and put it to the Operation's messeages collection.
                                        MessagePart part = inHeaderMessage.Parts[0];
                                        if (part != null)
                                        {
                                            Message simpleInHeaderMessage = new Message();
                                            simpleInHeaderMessage.Name = inHeaderMessage.Name;
                                            simpleInHeaderMessage.Element.ElementName      = part.Element.Name;
                                            simpleInHeaderMessage.Element.ElementNamespace = part.Element.Namespace;

                                            simpleOp.MessagesCollection.Add(simpleInHeaderMessage);
                                        }
                                        else
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message part");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // WSDL modified.
                                throw new WsdlModifiedException("Could not find the operation binding");
                            }

                            if (simpleOp.Mep == Mep.RequestResponse && opBinding.Output != null)
                            {
                                // Enumerate the message headers for the output message.
                                foreach (ServiceDescriptionFormatExtension extension in opBinding.Output.Extensions)
                                {
                                    SoapHeaderBinding outHeader = extension as SoapHeaderBinding;
                                    if (outHeader != null)
                                    {
                                        // Create the in header and add it to the headers collection.
                                        MessageHeader simpleOutHeader  = new MessageHeader();
                                        FxMessage     outHeaderMessage = srvDesc.Messages[outHeader.Message.Name];

                                        if (outHeaderMessage == null)
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message");
                                        }

                                        simpleOutHeader.Name    = outHeaderMessage.Name;
                                        simpleOutHeader.Message = outHeaderMessage.Name;
                                        simpleOp.MessagesCollection[1].HeadersCollection.Add(simpleOutHeader);

                                        // Create the out header message and put it to the Operation's messeages collection.
                                        MessagePart part = outHeaderMessage.Parts[0];
                                        if (part != null)
                                        {
                                            Message simpleOutHeaderMessage = new Message();
                                            simpleOutHeaderMessage.Name = outHeaderMessage.Name;
                                            simpleOutHeaderMessage.Element.ElementName      = part.Element.Name;
                                            simpleOutHeaderMessage.Element.ElementNamespace = part.Element.Namespace;

                                            simpleOp.MessagesCollection.Add(simpleOutHeaderMessage);
                                        }
                                        else
                                        {
                                            // WSDL is modified.
                                            throw new WsdlModifiedException("Could not find the message part");
                                        }
                                    }
                                }
                            }
                            else if (simpleOp.Mep == Mep.RequestResponse)
                            {
                                // WSDL modified.
                                throw new WsdlModifiedException("Could not find the operation binding");
                            }
                        }
                    }
                }
            }

            // Check for the "Generate service tags" option.
            if (srvDesc.Services.Count == 1)
            {
                simpleContract.NeedsServiceElement = true;
            }

            // Turn on the SOAP 1.2 binding if available.
            foreach (System.Web.Services.Description.Binding binding in srvDesc.Bindings)
            {
                if (binding.Extensions.Find(typeof(Soap12Binding)) != null)
                {
                    simpleContract.Bindings |= InterfaceContract.SoapBindings.Soap12;
                }
            }

            return(simpleContract);
        }
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("SoapBindingStyleInput_cs.wsdl");
        Binding myBinding = new Binding();

        myBinding.Name = "SOAPSvrMgr_SOAPBinding";
        myBinding.Type = new XmlQualifiedName("tns:SOAPSvrMgr_portType");

// <Snippet1>
        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        // Message to be transmitted contains parameters to call a procedure.
        mySoapBinding.Style = SoapBindingStyle.Rpc;
        myBinding.Extensions.Add(mySoapBinding);
// </Snippet1>

        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "GetServerStats";

        SoapOperationBinding mySoapOperationBinding =
            new SoapOperationBinding();

        mySoapOperationBinding.SoapAction =
            "http://tempuri.org/soapsvcmgr/GetServerStats";
        myOperationBinding.Extensions.Add(mySoapOperationBinding);

        // Create InputBinding for operation for the 'SOAP' protocol.
        InputBinding myInputBinding = new InputBinding();
// <Snippet2>
// <Snippet3>
// <Snippet4>
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        // Encode SOAP body using rules specified by the 'Encoding' property.
        mySoapBodyBinding.Use = SoapBindingUse.Encoded;
        // Set URI representing the encoding style for encoding the body.
        mySoapBodyBinding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/";
        // Set the Uri representing the location of the specification
        // for encoding of content not defined by 'Encoding' property'.
        mySoapBodyBinding.Namespace = "http://tempuri.org/soapsvcmgr/";
        myInputBinding.Extensions.Add(mySoapBodyBinding);
// </Snippet4>
// </Snippet3>
// </Snippet2>

// <Snippet5>
// <Snippet6>
        SoapHeaderBinding mySoapHeaderBinding = new SoapHeaderBinding();

        mySoapHeaderBinding.Message =
            new XmlQualifiedName("tns:Soapsvcmgr_Headers_Request");
        mySoapHeaderBinding.Part = "AuthCS";
        // Encode SOAP header using rules specified by the 'Encoding' property.
        mySoapHeaderBinding.Use = SoapBindingUse.Encoded;
        // Set URI representing the encoding style for encoding the header.
        mySoapHeaderBinding.Encoding = "http://schemas.xmlsoap.org/soap/encoding/";
        // Set the Uri representing the location of the specification
        // for encoding of content not defined by 'Encoding' property'.
        mySoapHeaderBinding.Namespace = "http://tempuri.org/SOAPSvr/soapsvcmgr/headers.xsd";
        // Add mySoapHeaderBinding to the 'myInputBinding' object.
        myInputBinding.Extensions.Add(mySoapHeaderBinding);
// </Snippet5>
// </Snippet6>
        // Create OutputBinding for operation.
        OutputBinding myOutputBinding = new OutputBinding();

        myOutputBinding.Extensions.Add(mySoapBodyBinding);
        mySoapHeaderBinding.Part    = "AuthSC";
        mySoapHeaderBinding.Message =
            new XmlQualifiedName("tns:Soapsvcmgr_Headers_Response");
        myOutputBinding.Extensions.Add(mySoapHeaderBinding);

        // Add 'InputBinding' and 'OutputBinding' to 'OperationBinding'.
        myOperationBinding.Input  = myInputBinding;
        myOperationBinding.Output = myOutputBinding;
        myBinding.Operations.Add(myOperationBinding);

        myServiceDescription.Bindings.Add(myBinding);
        myServiceDescription.Write("SoapBindingStyleOutput_cs.wsdl");
        Console.WriteLine("'SoapBindingStyleOutput_cs.wsdl' file is generated.");
        Console.WriteLine("Proxy could be created using command" +
                          " 'wsdl SoapBindingStyleOutput_cs.wsdl'");
    }