// <Snippet8>
    // Used to create OperationBinding instances within 'Binding'.
    public static OperationBinding CreateOperationBinding(string operation, string targetNamespace)
    {
        // Create OperationBinding instance for operation.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = operation;
        // Create InputBinding for operation.
        InputBinding    myInputBinding    = new InputBinding();
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use = SoapBindingUse.Literal;
        myInputBinding.Extensions.Add(mySoapBodyBinding);
        // Create OutputBinding for operation.
        OutputBinding myOutputBinding = new OutputBinding();

        myOutputBinding.Extensions.Add(mySoapBodyBinding);
        // Add 'InputBinding' and 'OutputBinding' to 'OperationBinding'.
        myOperationBinding.Input  = myInputBinding;
        myOperationBinding.Output = myOutputBinding;
        // Create extensibility element for 'SoapOperationBinding'.
        SoapOperationBinding mySoapOperationBinding = new SoapOperationBinding();

        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        mySoapOperationBinding.SoapAction = targetNamespace + operation;
        // Add extensibility element 'SoapOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(mySoapOperationBinding);
        return(myOperationBinding);
    }
Пример #2
0
    public static MessageBinding CreateInputOutputBinding(string myBindName,
                                                          bool isInputBinding)
    {
// <Snippet2>

        // Value isInputBinding = true ---> return type = InputBinding.
        // Value isInputBinding = false --> return type = OutputBinding.
// <Snippet3>
// <Snippet4>
        MessageBinding myMessageBinding = null;

        switch (isInputBinding)
        {
        case true:
            myMessageBinding = new InputBinding();
            Console.WriteLine("Added an InputBinding");
            break;

        case false:
            myMessageBinding = new OutputBinding();
            Console.WriteLine("Added an OutputBinding");
            break;
        }
// </Snippet2>
        myMessageBinding.Name = myBindName;
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use = SoapBindingUse.Literal;
        myMessageBinding.Extensions.Add(mySoapBodyBinding);
        Console.WriteLine("Added extensibility element of type : " +
                          mySoapBodyBinding.GetType());
// </Snippet3>
// </Snippet4>
        return(myMessageBinding);
    }
Пример #3
0
            private static SoapBodyBinding ConvertSoapBodyBinding(SoapBodyBinding src, EnvelopeVersion version)
            {
                if (version == EnvelopeVersion.None)
                {
                    return(null);
                }
                EnvelopeVersion bindingVersion = GetBindingVersion <Soap12BodyBinding>(src);

                if (bindingVersion == version)
                {
                    return(src);
                }
                SoapBodyBinding binding = (version == EnvelopeVersion.Soap12) ? new Soap12BodyBinding() : new SoapBodyBinding();

                if (src != null)
                {
                    if (XmlSerializerOperationFormatter.GetEncoding(bindingVersion) == src.Encoding)
                    {
                        binding.Encoding = XmlSerializerOperationFormatter.GetEncoding(version);
                    }
                    binding.Encoding    = XmlSerializerOperationFormatter.GetEncoding(version);
                    binding.Namespace   = src.Namespace;
                    binding.Parts       = src.Parts;
                    binding.PartsString = src.PartsString;
                    binding.Use         = src.Use;
                    binding.Required    = src.Required;
                }
                return(binding);
            }
Пример #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
        void CreateOutputBinding(ServiceEndpoint endpoint, OperationBinding op_binding,
                                 MessageDescription sm_md)
        {
            var out_binding = new OutputBinding();

            op_binding.Output = out_binding;

            var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None;

            if (message_version == MessageVersion.None)
            {
                return;
            }

            SoapBodyBinding soap_body_binding;

            if (message_version.Envelope == EnvelopeVersion.Soap11)
            {
                soap_body_binding = new SoapBodyBinding();
            }
            else if (message_version.Envelope == EnvelopeVersion.Soap12)
            {
                soap_body_binding = new Soap12BodyBinding();
            }
            else
            {
                throw new InvalidOperationException();
            }

            soap_body_binding.Use = SoapBindingUse.Literal;
            out_binding.Extensions.Add(soap_body_binding);
        }
Пример #6
0
            private void MoveToMethod(MethodInfo targetMethod)
            {
                operation            = GetOperation(this.wsDescriptions, this.wsBinding, targetMethod);
                operationBinding     = GetOperationBinding(operation, this.wsBinding);
                soapOperationBinding = (SoapOperationBinding)operationBinding.Extensions.Find(typeof(SoapOperationBinding));

                string          inputMessageName     = (!StringUtils.IsNullOrEmpty(operationBinding.Input.Name) && (soapOperationBinding.Style != SoapBindingStyle.Rpc)) ? operationBinding.Input.Name : operation.Name;
                SoapBodyBinding inputSoapBodyBinding = (SoapBodyBinding)operationBinding.Input.Extensions.Find(typeof(SoapBodyBinding));

#if !NET_2_0
                if (soapOperationBinding.Style == SoapBindingStyle.Rpc &&
                    inputSoapBodyBinding.Use == SoapBindingUse.Literal)
                {
                    throw new NotSupportedException("rpc-literal SOAP messages are not supported on .NET Framework 1.1");
                }
#endif
                if (inputSoapBodyBinding.Use != SoapBindingUse.Literal)
                {
                    throw new NotSupportedException("WebServiceProxyFactory only supports document-literal and rpc-literal SOAP messages to conform to WS-I Basic Profiles.");
                }

                Message inputMessage = this.wsDescriptions.GetMessage(operation.Messages.Input.Message);
                inputMembersMapping = GetMembersMapping(inputMessageName, inputMessage.Parts, inputSoapBodyBinding, soapOperationBinding.Style);

                outputMembersMapping = null;
                if (operation.Messages.Output != null)
                {
                    string          outputMessageName     = (!StringUtils.IsNullOrEmpty(operationBinding.Output.Name) && (soapOperationBinding.Style != SoapBindingStyle.Rpc)) ? operationBinding.Output.Name : (operation.Name + "Response");
                    SoapBodyBinding outputSoapBodyBinding = (SoapBodyBinding)operationBinding.Output.Extensions.Find(typeof(SoapBodyBinding));
                    Message         outputMessage         = this.wsDescriptions.GetMessage(operation.Messages.Output.Message);
                    outputMembersMapping = GetMembersMapping(outputMessageName, outputMessage.Parts, outputSoapBodyBinding, soapOperationBinding.Style);
                }
            }
    void GetOperationFormat(OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse inputUse, out SoapBindingUse outputUse)
    {
        style     = SoapBindingStyle.Document;
        inputUse  = SoapBindingUse.Literal;
        outputUse = SoapBindingUse.Literal;
        if (obin.Extensions != null)
        {
            SoapOperationBinding sob = obin.Extensions.Find(typeof(SoapOperationBinding)) as SoapOperationBinding;
            if (sob != null)
            {
                style = sob.Style;
                if (obin.Input != null)
                {
                    SoapBodyBinding sbb0 = obin.Input.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding;
                    if (sbb0 != null)
                    {
                        inputUse = sbb0.Use;
                    }
                }

                if (obin.Output != null)
                {
                    SoapBodyBinding sbb1 = obin.Output.Extensions.Find(typeof(SoapBodyBinding)) as SoapBodyBinding;
                    if (sbb1 != null)
                    {
                        outputUse = sbb1.Use;
                    }
                }
            }
        }
    }
Пример #8
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'.");
    }
Пример #9
0
        void WriteBody(XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
        {
            Message msg = descriptions.GetMessage(opm.Message);

            if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
            {
                MessagePart part = msg.Parts[0];
                if (part.Element == XmlQualifiedName.Empty)
                {
                    WriteTypeSample(xtw, part.Type);
                }
                else
                {
                    WriteRootElementSample(xtw, part.Element);
                }
            }
            else
            {
                string elemName = oper.Name;
                string ns       = "";
                if (opm is OperationOutput)
                {
                    elemName += "Response";
                }

                if (style == SoapBindingStyle.Rpc)
                {
                    xtw.WriteStartElement(elemName, sbb.Namespace);
                    ns = sbb.Namespace;
                }

                foreach (MessagePart part in msg.Parts)
                {
                    if (part.Element == XmlQualifiedName.Empty)
                    {
                        XmlSchemaElement elem = new XmlSchemaElement();
                        elem.SchemaTypeName = part.Type;
                        elem.Name           = part.Name;
                        WriteElementSample(xtw, ns, elem);
                    }
                    else
                    {
                        WriteRootElementSample(xtw, part.Element);
                    }
                }

                if (style == SoapBindingStyle.Rpc)
                {
                    xtw.WriteEndElement();
                }
            }
            WriteQueuedTypeSamples(xtw);
        }
Пример #10
0
        internal static SoapBodyBinding GetOrCreateSoapBodyBinding(WsdlEndpointConversionContext endpointContext, MessageBinding wsdlMessageBinding, WsdlExporter exporter)
        {
            if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
            {
                return(null);
            }
            SoapBodyBinding soapBodyBinding = GetSoapBodyBinding(endpointContext, wsdlMessageBinding);
            EnvelopeVersion soapVersion     = GetSoapVersion(endpointContext.WsdlBinding);

            if (soapBodyBinding != null)
            {
                return(soapBodyBinding);
            }
            return(CreateSoapBodyBinding(soapVersion, wsdlMessageBinding));
        }
Пример #11
0
        private static SoapBodyBinding CreateSoapBodyBinding(EnvelopeVersion version, MessageBinding wsdlMessageBinding)
        {
            SoapBodyBinding extension = null;

            if (version == EnvelopeVersion.Soap12)
            {
                extension = new Soap12BodyBinding();
            }
            else if (version == EnvelopeVersion.Soap11)
            {
                extension = new SoapBodyBinding();
            }
            wsdlMessageBinding.Extensions.Add(extension);
            return(extension);
        }
        private static object GetSoapBodyBinding(System.ServiceModel.Channels.Binding binding)
        {
            if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap11)
            {
                SoapBodyBinding soapBinding = new SoapBodyBinding();
                soapBinding.Use = SoapBindingUse.Literal;
                return(soapBinding);
            }
            else if (binding.MessageVersion.Envelope == EnvelopeVersion.Soap12)
            {
                Soap12BodyBinding soap12Binding = new Soap12BodyBinding();
                soap12Binding.Use = SoapBindingUse.Literal;
                return(soap12Binding);
            }

            return(null);
        }
        void CheckBasicHttpBinding(WSServiceDescription wsd, string binding_name, XmlQualifiedName binding_type,
                                   string operation_name, string action, bool has_input, bool has_output, string label)
        {
            WSBinding        b  = GetBinding(wsd, binding_name, label);
            OperationBinding op = GetOperationBinding(b, operation_name, label + " CheckBasicHttpBinding");

            Assert.AreEqual(binding_type, b.Type, label + " #cbh0");

            if (has_input)
            {
                InputBinding inb = op.Input;
                Assert.IsNotNull(inb, label + " #cbh1");
                Assert.AreEqual(1, inb.Extensions.Count, label + " #cbh2");

                Assert.AreEqual(typeof(SoapBodyBinding), inb.Extensions [0].GetType(), label + " #cbh3");
                SoapBodyBinding soap_binding = (SoapBodyBinding)inb.Extensions [0];
                Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh4");

                if (action != null)
                {
                    Assert.AreEqual(1, op.Extensions.Count, label + " #chb5");
                    Assert.AreEqual(typeof(SoapOperationBinding), op.Extensions [0].GetType(), label + " #cbh6");
                    SoapOperationBinding sopb = (SoapOperationBinding)op.Extensions [0];
                    Assert.AreEqual(action, sopb.SoapAction, label + " #cbh7");
                }
            }

            if (has_output)
            {
                OutputBinding outb = op.Output;
                Assert.IsNotNull(outb, label + " #cbh10");
                Assert.AreEqual(1, outb.Extensions.Count, label + " #cbh11");

                Assert.AreEqual(typeof(SoapBodyBinding), outb.Extensions [0].GetType(), label + " #cbh12");
                SoapBodyBinding soap_binding = (SoapBodyBinding)outb.Extensions [0];
                Assert.AreEqual(SoapBindingUse.Literal, soap_binding.Use, label + " #cbh13");
            }

            Assert.AreEqual(1, b.Extensions.Count, label + " #cbh20");
            Assert.AreEqual(typeof(SoapBinding), b.Extensions [0].GetType(), label + " #cbh21");
            SoapBinding sb = (SoapBinding)b.Extensions [0];

            Assert.AreEqual(SoapBinding.HttpTransport, sb.Transport, label + " #cbh22");
        }
Пример #14
0
        void CreateInputBinding(ServiceEndpoint endpoint, OperationBinding op_binding,
                                MessageDescription sm_md)
        {
            var in_binding = new InputBinding();

            op_binding.Input = in_binding;

            var message_version = endpoint.Binding.MessageVersion ?? MessageVersion.None;

            if (message_version == MessageVersion.None)
            {
                return;
            }

            SoapBodyBinding      soap_body_binding;
            SoapOperationBinding soap_operation_binding;

            if (message_version.Envelope == EnvelopeVersion.Soap11)
            {
                soap_body_binding      = new SoapBodyBinding();
                soap_operation_binding = new SoapOperationBinding();
            }
            else if (message_version.Envelope == EnvelopeVersion.Soap12)
            {
                soap_body_binding      = new Soap12BodyBinding();
                soap_operation_binding = new Soap12OperationBinding();
            }
            else
            {
                throw new InvalidOperationException();
            }

            soap_body_binding.Use = SoapBindingUse.Literal;
            in_binding.Extensions.Add(soap_body_binding);

            //Set Action
            //<operation > <soap:operation soapAction .. >
            soap_operation_binding.SoapAction = sm_md.Action;
            soap_operation_binding.Style      = SoapBindingStyle.Document;
            op_binding.Extensions.Add(soap_operation_binding);
        }
Пример #15
0
            private void ExportMessageBodyBinding(MessageDescription messageDescription, bool isRpc, bool isEncoded, MessageBinding messageBinding)
            {
                SoapBodyBinding binding = SoapHelper.GetOrCreateSoapBodyBinding(this.endpointContext, messageBinding, this.exporter);

                if (binding != null)
                {
                    binding.Use = isEncoded ? SoapBindingUse.Encoded : SoapBindingUse.Literal;
                    if (isRpc)
                    {
                        string wrapperNamespace;
                        if (!this.ExportedMessages.WrapperNamespaces.TryGetValue(new MessageContractExporter.MessageDescriptionDictionaryKey(this.endpointContext.ContractConversionContext.Contract, messageDescription), out wrapperNamespace))
                        {
                            wrapperNamespace = messageDescription.Body.WrapperNamespace;
                        }
                        binding.Namespace = wrapperNamespace;
                    }
                    if (isEncoded)
                    {
                        binding.Encoding = XmlSerializerOperationFormatter.GetEncoding(this.soapVersion);
                    }
                }
            }
Пример #16
0
// </Snippet13>
// <Snippet3>
    // Used to create OperationBinding instances within 'Binding'.
    public static OperationBinding CreateOperationBinding(string operation,
                                                          string targetNamespace)
    {
        // Create OperationBinding for operation.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = operation;
// <Snippet1>
// <Snippet2>
        // Create InputBinding for operation.
        InputBinding    myInputBinding    = new InputBinding();
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use = SoapBindingUse.Literal;
        myInputBinding.Extensions.Add(mySoapBodyBinding);
// </Snippet2>
// </Snippet1>
        // Create OutputBinding for operation.
        OutputBinding myOutputBinding = new OutputBinding();

        myOutputBinding.Extensions.Add(mySoapBodyBinding);

        // Add InputBinding and OutputBinding to OperationBinding.
        myOperationBinding.Input  = myInputBinding;
        myOperationBinding.Output = myOutputBinding;

        // Create an extensibility element for SoapOperationBinding.
        SoapOperationBinding mySoapOperationBinding = new SoapOperationBinding();

        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        mySoapOperationBinding.SoapAction = targetNamespace + operation;

        // Add the extensibility element SoapOperationBinding to OperationBinding.
        myOperationBinding.Extensions.Add(mySoapOperationBinding);
        return(myOperationBinding);
    }
Пример #17
0
            /// <summary>
            /// Search and returns the type mapping between method parameters/return value
            /// and the element parts of a literal-use SOAP message.
            /// </summary>
            private XmlMembersMapping GetMembersMapping(string messageName, MessagePartCollection messageParts, SoapBodyBinding soapBodyBinding, SoapBindingStyle soapBindingStyle)
            {
#if NET_2_0
                if (soapBindingStyle == SoapBindingStyle.Rpc)
                {
                    SoapSchemaMember[] soapSchemaMembers = new SoapSchemaMember[messageParts.Count];
                    for (int i = 0; i < messageParts.Count; i++)
                    {
                        SoapSchemaMember ssm = new SoapSchemaMember();
                        ssm.MemberName       = messageParts[i].Name;
                        ssm.MemberType       = messageParts[i].Type;
                        soapSchemaMembers[i] = ssm;
                    }
                    return(this.schemaImporter.ImportMembersMapping(messageName, soapBodyBinding.Namespace, soapSchemaMembers));
                }
                else
                {
                    return(this.schemaImporter.ImportMembersMapping(messageParts[0].Element));
                }
#else
                return(this.schemaImporter.ImportMembersMapping(messageParts[0].Element));
#endif
            }
    static void Main()
    {
        try
        {
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("MathService_input_cs.wsdl");
            string myTargetNamespace = myServiceDescription.TargetNamespace;

// <Snippet2>
// <Snippet3>
            // Create an OperationBinding for the Add operation.
            OperationBinding addOperationBinding = new OperationBinding();
            string           addOperation        = "Add";
            addOperationBinding.Name = addOperation;
// </Snippet3>

// <Snippet4>
            // Create an InputBinding for the Add operation.
            InputBinding    myInputBinding    = new InputBinding();
            SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();
            mySoapBodyBinding.Use = SoapBindingUse.Literal;
            myInputBinding.Extensions.Add(mySoapBodyBinding);

            // Add the InputBinding to the OperationBinding.
            addOperationBinding.Input = myInputBinding;
// </Snippet4>

// <Snippet5>
            // Create an OutputBinding for the Add operation.
            OutputBinding myOutputBinding = new OutputBinding();
            myOutputBinding.Extensions.Add(mySoapBodyBinding);

            // Add the OutputBinding to the OperationBinding.
            addOperationBinding.Output = myOutputBinding;
// </Snippet5>

// <Snippet6>
            // Create an extensibility element for a SoapOperationBinding.
            SoapOperationBinding mySoapOperationBinding =
                new SoapOperationBinding();
            mySoapOperationBinding.Style      = SoapBindingStyle.Document;
            mySoapOperationBinding.SoapAction = myTargetNamespace + addOperation;

            // Add the extensibility element SoapOperationBinding to
            // the OperationBinding.
            addOperationBinding.Extensions.Add(mySoapOperationBinding);
// </Snippet6>
// </Snippet2>

// <Snippet7>
            ServiceDescriptionFormatExtensionCollection myExtensions;

            // Get the FaultBindingCollection from the OperationBinding.
            FaultBindingCollection myFaultBindingCollection =
                addOperationBinding.Faults;
            FaultBinding myFaultBinding = new FaultBinding();
            myFaultBinding.Name = "ErrorFloat";

            // Associate SOAP fault binding to the fault binding of the operation.
            myExtensions = myFaultBinding.Extensions;
            SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();
            mySoapFaultBinding.Use       = SoapBindingUse.Literal;
            mySoapFaultBinding.Namespace = myTargetNamespace;
            myExtensions.Add(mySoapFaultBinding);
            myFaultBindingCollection.Add(myFaultBinding);
// </Snippet7>

            // Get the BindingCollection from the ServiceDescription.
            BindingCollection myBindingCollection =
                myServiceDescription.Bindings;

            // Get the OperationBindingCollection of SOAP binding
            // from the BindingCollection.
            OperationBindingCollection myOperationBindingCollection =
                myBindingCollection[0].Operations;
            myOperationBindingCollection.Add(addOperationBinding);

            Console.WriteLine(
                "The operations supported by this service are:");
            foreach (OperationBinding myOperationBinding in
                     myOperationBindingCollection)
            {
// <Snippet8>
                Binding myBinding = myOperationBinding.Binding;
                Console.WriteLine(" Binding : " + myBinding.Name +
                                  " :: Name of operation : " + myOperationBinding.Name);
// </Snippet8>
                FaultBindingCollection myFaultBindingCollection1 =
                    myOperationBinding.Faults;
                foreach (FaultBinding myFaultBinding1 in
                         myFaultBindingCollection1)
                {
                    Console.WriteLine("    Fault : " + myFaultBinding1.Name);
                }
            }
            // Save the ServiceDescription to an external file.
            myServiceDescription.Write("MathService_new_cs.wsdl");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
Пример #19
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);
        }
Пример #20
0
    public static void Main()
    {
        ServiceDescription myDescription =
            ServiceDescription.Read("AddNumbersInput_cs.wsdl");
        // Create a 'Binding' object for the 'SOAP' protocol.
        Binding myBinding = new Binding();

        myBinding.Name = "Service1Soap";
        XmlQualifiedName qualifiedName =
            new XmlQualifiedName("s0:Service1Soap");

        myBinding.Type = qualifiedName;

// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        mySoapBinding.Style     = SoapBindingStyle.Document;
        // Add the 'SoapBinding' object to the 'Binding' object.
        myBinding.Extensions.Add(mySoapBinding);
// </Snippet4>
// </Snippet3>
// </Snippet2>
// </Snippet1>

        // Create the 'OperationBinding' object for the 'SOAP' protocol.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";

// <Snippet5>
// <Snippet6>
// <Snippet7>
        // Create the 'SoapOperationBinding' object for the 'SOAP' protocol.
        SoapOperationBinding mySoapOperationBinding =
            new SoapOperationBinding();

        mySoapOperationBinding.SoapAction = "http://tempuri.org/AddNumbers";
        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        // Add the 'SoapOperationBinding' object to 'OperationBinding' object.
        myOperationBinding.Extensions.Add(mySoapOperationBinding);
// </Snippet7>
// </Snippet6>
// </Snippet5>

// <Snippet8>
// <Snippet9>
// <Snippet10>
        // Create the 'InputBinding' object for the 'SOAP' protocol.
        InputBinding    myInput        = new InputBinding();
        SoapBodyBinding mySoapBinding1 = new SoapBodyBinding();

        mySoapBinding1.Use = SoapBindingUse.Literal;
        myInput.Extensions.Add(mySoapBinding1);
        // Add the 'InputBinding' object to 'OperationBinding' object.
        myOperationBinding.Input = myInput;
        // Create the 'OutputBinding' object'.
        OutputBinding myOutput = new OutputBinding();

        myOutput.Extensions.Add(mySoapBinding1);
        // Add the 'OutputBinding' object to 'OperationBinding' object.
        myOperationBinding.Output = myOutput;
        // Add the 'OperationBinding' object to 'Binding' object.
        myBinding.Operations.Add(myOperationBinding);
        // Add the 'Binding' object to the ServiceDescription instance.
        myDescription.Bindings.Add(myBinding);
// </Snippet10>
// </Snippet9>
// </Snippet8>

// <Snippet11>
// <Snippet12>
        Port soapPort = new Port();

        soapPort.Name    = "Service1Soap";
        soapPort.Binding = new XmlQualifiedName("s0:Service1Soap");
        // Create a 'SoapAddressBinding' object for the 'SOAP' protocol.
        SoapAddressBinding mySoapAddressBinding =
            new SoapAddressBinding();

        mySoapAddressBinding.Location = "http://localhost/Service1_cs.asmx";
        // Add the 'SoapAddressBinding' object to the 'Port'.
        soapPort.Extensions.Add(mySoapAddressBinding);
        // Add the 'Port' object to the ServiceDescription instance.
        myDescription.Services[0].Ports.Add(soapPort);
// </Snippet12>
// </Snippet11>

        // Create a 'PortType' object. for SOAP protocol.
        PortType soapPortType = new PortType();

        soapPortType.Name = "Service1Soap";
        Operation soapOperation = new Operation();

        soapOperation.Name = "AddNumbers";

        OperationMessage soapInput = (OperationMessage) new OperationInput();

        soapInput.Message = new XmlQualifiedName("s0:AddNumbersSoapIn");
        OperationMessage soapOutput = (OperationMessage) new OperationOutput();

        soapOutput.Message = new XmlQualifiedName("s0:AddNumbersSoapOut");

        soapOperation.Messages.Add(soapInput);
        soapOperation.Messages.Add(soapOutput);

        // Add the 'Operation' object to 'PortType' object.
        soapPortType.Operations.Add(soapOperation);

        // Add the 'PortType' object first to 'PortTypeCollection' object
        // and then to 'ServiceDescription' object.
        myDescription.PortTypes.Add(soapPortType);

        // Create the 'Message' object.
        Message soapMessage1 = new Message();

        soapMessage1.Name = "AddNumbersSoapIn";
        // Create the 'MessageParts' object.
        MessagePart soapMessagePart1 = new MessagePart();

        soapMessagePart1.Name    = "parameters";
        soapMessagePart1.Element = new XmlQualifiedName("s0:AddNumbers");

        // Add the 'MessagePart' object to 'Messages' object.
        soapMessage1.Parts.Add(soapMessagePart1);

        // Create another 'Message' object.
        Message soapMessage2 = new Message();

        soapMessage2.Name = "AddNumbersSoapOut";

        MessagePart soapMessagePart2 = new MessagePart();

        soapMessagePart2.Name    = "parameters";
        soapMessagePart2.Element =
            new XmlQualifiedName("s0:AddNumbersResponse");
        // Add the 'MessagePart' object to second 'Message' object.
        soapMessage2.Parts.Add(soapMessagePart2);

        // Add the 'Message' objects to 'ServiceDescription'.
        myDescription.Messages.Add(soapMessage1);
        myDescription.Messages.Add(soapMessage2);

        // Write the 'ServiceDescription' object as a WSDL file.
        myDescription.Write("AddNumbersOut_cs.wsdl");
        Console.WriteLine(" 'AddNumbersOut_cs.Wsdl' file was generated");
    }
Пример #21
0
    public static void Main()
    {
        try
        {
            // Input wsdl file.
            string myInputWsdlFile = "SoapFaultInput_cs.wsdl";
            // Output wsdl file.
            string myOutputWsdlFile = "SoapFaultOutput_cs.wsdl";
            // Initialize an instance of a 'ServiceDescription' object.
            ServiceDescription myServiceDescription =
                ServiceDescription.Read(myInputWsdlFile);
            // Get a SOAP binding object with binding name "MyService1Soap".
            Binding myBinding = myServiceDescription.Bindings["MyService1Soap"];
            // Create the 'OperationBinding' object for the 'SOAP' protocol.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "Add";

            // Create the 'SoapOperationBinding' object for the 'SOAP' protocol.
            SoapOperationBinding mySoapOperationBinding =
                new SoapOperationBinding();
            mySoapOperationBinding.SoapAction = "http://tempuri.org/Add";
            mySoapOperationBinding.Style      = SoapBindingStyle.Document;
            // Add the 'SoapOperationBinding' object to 'OperationBinding' object.
            myOperationBinding.Extensions.Add(mySoapOperationBinding);
// <Snippet1>
            // Create the 'InputBinding' object for the 'SOAP' protocol.
            InputBinding    myInput        = new InputBinding();
            SoapBodyBinding mySoapBinding1 = new SoapBodyBinding();
            mySoapBinding1.PartsString = "parameters";
            mySoapBinding1.Use         = SoapBindingUse.Literal;
            myInput.Extensions.Add(mySoapBinding1);
            // Assign the 'InputBinding' to 'OperationBinding'.
            myOperationBinding.Input = myInput;
            // Create the 'OutputBinding' object' for the 'SOAP' protocol..
            OutputBinding myOutput = new OutputBinding();
            myOutput.Extensions.Add(mySoapBinding1);
            // Assign the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutput;
// </Snippet1>

// <Snippet2>
// <Snippet3>
// <Snippet4>
// <Snippet5>

            // Create a new instance of 'SoapFaultBinding' class.
            SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();
            // Encode fault message using rules specified by 'Encoding' property.
            mySoapFaultBinding.Use = SoapBindingUse.Encoded;
            // Set the URI representing the encoding style.
            mySoapFaultBinding.Encoding = "http://tempuri.org/stockquote";
            // Set the URI representing the location of the specification
            // for encoding of content not defined by 'Encoding' property'.
            mySoapFaultBinding.Namespace = "http://tempuri.org/stockquote";
            // Create a new instance of 'FaultBinding'.
            FaultBinding myFaultBinding = new FaultBinding();
            myFaultBinding.Name = "AddFaultbinding";
            myFaultBinding.Extensions.Add(mySoapFaultBinding);
            // Get existing 'OperationBinding' object.
            myOperationBinding.Faults.Add(myFaultBinding);
            myBinding.Operations.Add(myOperationBinding);

// </Snippet5>
// </Snippet4>
// </Snippet3>
// </Snippet2>

            // Create a new wsdl file.
            myServiceDescription.Write(myOutputWsdlFile);
            Console.WriteLine("The new wsdl file created is :"
                              + myOutputWsdlFile);
            Console.WriteLine("Proxy could be created using command : wsdl "
                              + myOutputWsdlFile);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error occurred : " + e.Message);
        }
    }
Пример #22
0
    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'");
    }
Пример #23
0
    public static void Main()
    {
        ServiceDescription myDescription =
            ServiceDescription.Read("AddNumbersInput_cs.wsdl");
        // Create a 'Binding' object for the 'SOAP' protocol.
        Binding myBinding = new Binding();

        myBinding.Name = "Service1Soap";
        XmlQualifiedName qualifiedName =
            new XmlQualifiedName("s0:Service1Soap");

        myBinding.Type = qualifiedName;
// <Snippet1>
        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        mySoapBinding.Style     = SoapBindingStyle.Document;
        // Get the URI for XML namespace of the SoapBinding class.
        String myNameSpace = SoapBinding.Namespace;

        Console.WriteLine("The URI of the XML Namespace is :" + myNameSpace);
// </Snippet1>

        // Add the 'SoapBinding'  object to the 'Binding' object.
        myBinding.Extensions.Add(mySoapBinding);

        // Create the 'OperationBinding' object for the 'SOAP' protocol.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";

        // Create the 'SoapOperationBinding' object for the 'SOAP' protocol.
        SoapOperationBinding mySoapOperationBinding =
            new SoapOperationBinding();

        mySoapOperationBinding.SoapAction = "http://tempuri.org/AddNumbers";
        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        // Add the 'SoapOperationBinding' object to 'OperationBinding' object.
        myOperationBinding.Extensions.Add(mySoapOperationBinding);

// <Snippet2>
        // Create the 'InputBinding' object for the 'SOAP' protocol.
        InputBinding    myInput        = new InputBinding();
        SoapBodyBinding mySoapBinding1 = new SoapBodyBinding();

        mySoapBinding1.Use = SoapBindingUse.Literal;

        String[] myParts = new String[1];
        myParts[0] = "parameters";
        // Set the names of the message parts to appear in the SOAP body.
        mySoapBinding1.Parts = myParts;
        myInput.Extensions.Add(mySoapBinding1);
        // Add the 'InputBinding' object to 'OperationBinding' object.
        myOperationBinding.Input = myInput;
        // Create the 'OutputBinding' object'.
        OutputBinding myOutput = new OutputBinding();

        myOutput.Extensions.Add(mySoapBinding1);
        // Add the 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutput;
// </Snippet2>
        // Add the 'OperationBinding' to 'Binding'.
        myBinding.Operations.Add(myOperationBinding);

        // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
        myDescription.Bindings.Add(myBinding);

        // Write the 'ServiceDescription' as a WSDL file.
        myDescription.Write("AddNumbersOut_cs.wsdl");
        Console.WriteLine(" 'AddNumbersOut_cs.Wsdl' file was generated");
    }
Пример #24
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);
        }
        void ExportEndpoint(ServiceEndpoint endpoint, bool rejectDuplicate)
        {
            List <IWsdlExportExtension> extensions = ExportContractInternal(endpoint.Contract, rejectDuplicate);

            //FIXME: Namespace
            WSServiceDescription sd = GetServiceDescription("http://tempuri.org/");

            if (sd.TargetNamespace != endpoint.Contract.Namespace)
            {
                sd.Namespaces.Add("i0", endpoint.Contract.Namespace);

                //Import
                Import import = new Import();
                import.Namespace = endpoint.Contract.Namespace;

                sd.Imports.Add(import);
            }

            if (endpoint.Binding == null)
            {
                throw new ArgumentException(String.Format(
                                                "Binding for ServiceEndpoint named '{0}' is null",
                                                endpoint.Name));
            }

            bool msg_version_none =
                endpoint.Binding.MessageVersion != null &&
                endpoint.Binding.MessageVersion.Equals(MessageVersion.None);
            //ExportBinding
            WSBinding ws_binding = new WSBinding();

            //<binding name = ..
            ws_binding.Name = String.Concat(endpoint.Binding.Name, "_", endpoint.Contract.Name);

            //<binding type = ..
            ws_binding.Type = new QName(endpoint.Contract.Name, endpoint.Contract.Namespace);
            sd.Bindings.Add(ws_binding);

            if (!msg_version_none)
            {
                SoapBinding soap_binding = new SoapBinding();
                soap_binding.Transport = SoapBinding.HttpTransport;
                soap_binding.Style     = SoapBindingStyle.Document;
                ws_binding.Extensions.Add(soap_binding);
            }

            //	<operation
            foreach (OperationDescription sm_op in endpoint.Contract.Operations)
            {
                OperationBinding op_binding = new OperationBinding();
                op_binding.Name = sm_op.Name;

                //FIXME: Move to IWsdlExportExtension .. ?
                foreach (MessageDescription sm_md in sm_op.Messages)
                {
                    if (sm_md.Direction == MessageDirection.Input)
                    {
                        //<input
                        InputBinding in_binding = new InputBinding();

                        if (!msg_version_none)
                        {
                            SoapBodyBinding soap_body_binding = new SoapBodyBinding();
                            soap_body_binding.Use = SoapBindingUse.Literal;
                            in_binding.Extensions.Add(soap_body_binding);

                            //Set Action
                            //<operation > <soap:operation soapAction .. >
                            SoapOperationBinding soap_operation_binding = new SoapOperationBinding();
                            soap_operation_binding.SoapAction = sm_md.Action;
                            soap_operation_binding.Style      = SoapBindingStyle.Document;
                            op_binding.Extensions.Add(soap_operation_binding);
                        }

                        op_binding.Input = in_binding;
                    }
                    else
                    {
                        //<output
                        OutputBinding out_binding = new OutputBinding();

                        if (!msg_version_none)
                        {
                            SoapBodyBinding soap_body_binding = new SoapBodyBinding();
                            soap_body_binding.Use = SoapBindingUse.Literal;
                            out_binding.Extensions.Add(soap_body_binding);
                        }

                        op_binding.Output = out_binding;
                    }
                }

                ws_binding.Operations.Add(op_binding);
            }

            //Add <service
            Port ws_port = ExportService(sd, ws_binding, endpoint.Address, msg_version_none);

            //Call IWsdlExportExtension.ExportEndpoint
            WsdlContractConversionContext contract_context = new WsdlContractConversionContext(
                endpoint.Contract, sd.PortTypes [endpoint.Contract.Name]);
            WsdlEndpointConversionContext endpoint_context = new WsdlEndpointConversionContext(
                contract_context, endpoint, ws_port, ws_binding);

            if (extensions != null)
            {
                foreach (IWsdlExportExtension extn in extensions)
                {
                    extn.ExportEndpoint(this, endpoint_context);
                }
            }
        }
Пример #26
0
 public void InitializeSoapBodyBinding()
 {
     sbb = new SoapBodyBinding();
 }
Пример #27
0
    public static void Main()
    {
        ServiceDescription myDescription =
            ServiceDescription.Read("AddNumbersInput_cs.wsdl");
        // Create a 'Binding' object for the 'SOAP' protocol.
        Binding myBinding = new Binding();

        myBinding.Name = "Service1Soap";
        XmlQualifiedName qualifiedName =
            new XmlQualifiedName("s0:Service1Soap");

        myBinding.Type = qualifiedName;

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

        mySoapBinding.Transport = SoapBinding.HttpTransport;
        mySoapBinding.Style     = SoapBindingStyle.Document;
// </Snippet5>
        // Add the 'SoapBinding' object to the 'Binding' object.
        myBinding.Extensions.Add(mySoapBinding);

        // Create the 'OperationBinding' object for the 'SOAP' protocol.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";

        // Create the 'SoapOperationBinding' object for the 'SOAP' protocol.
        SoapOperationBinding mySoapOperationBinding =
            new SoapOperationBinding();

        mySoapOperationBinding.SoapAction = "http://tempuri.org/AddNumbers";
        mySoapOperationBinding.Style      = SoapBindingStyle.Document;
        // Add the 'SoapOperationBinding' object to 'OperationBinding' object.
        myOperationBinding.Extensions.Add(mySoapOperationBinding);

        // Create the 'InputBinding' object for the 'SOAP' protocol.
        InputBinding    myInput        = new InputBinding();
        SoapBodyBinding mySoapBinding1 = new SoapBodyBinding();

        mySoapBinding1.Use = SoapBindingUse.Literal;
        myInput.Extensions.Add(mySoapBinding1);
        // Assign the 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInput;
        // Create the 'OutputBinding' object' for the 'SOAP' protocol..
        OutputBinding myOutput = new OutputBinding();

        myOutput.Extensions.Add(mySoapBinding1);
        // Assign the 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutput;

        // Add the 'OperationBinding' to 'Binding'.
        myBinding.Operations.Add(myOperationBinding);

        // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
        myDescription.Bindings.Add(myBinding);

        Port soapPort = new Port();

        soapPort.Name    = "Service1Soap";
        soapPort.Binding = new XmlQualifiedName("s0:Service1Soap");

        // Create a 'SoapAddressBinding' object for the 'SOAP' protocol.
        SoapAddressBinding mySoapAddressBinding =
            new SoapAddressBinding();

        mySoapAddressBinding.Location = "http://localhost/AddNumbers.cs.asmx";

        // Add the 'SoapAddressBinding' to the 'Port'.
        soapPort.Extensions.Add(mySoapAddressBinding);

        // Add the 'Port' to 'PortCollection' of 'ServiceDescription'.
        myDescription.Services[0].Ports.Add(soapPort);

        // Write the 'ServiceDescription' as a WSDL file.
        myDescription.Write("AddNumbersOut_cs.wsdl");
        Console.WriteLine(" 'AddNumbersOut_cs.Wsdl' file was generated");
    }
Пример #28
0
    public static void Main()
    {
        ServiceDescription myServiceDescription = new ServiceDescription();

        myServiceDescription.Name            = "StockQuote";
        myServiceDescription.TargetNamespace = "http://www.contoso.com/stockquote.wsdl";

        // Generate the 'Types' element.
        XmlSchema myXmlSchema = new XmlSchema();

        myXmlSchema.AttributeFormDefault = XmlSchemaForm.Qualified;
        myXmlSchema.ElementFormDefault   = XmlSchemaForm.Qualified;
        myXmlSchema.TargetNamespace      = "http://www.contoso.com/stockquote.wsdl";

        //XmlSchemaElement myXmlSchemaElement;
        XmlSchemaComplexType myXmlSchemaComplexType = new XmlSchemaComplexType();

        myXmlSchemaComplexType.Name = "GetTradePriceInputType";
        XmlSchemaSequence myXmlSchemaSequence = new XmlSchemaSequence();

        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "tickerSymbol", true, new XmlQualifiedName("s:string")));
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "time", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceOutputType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "result", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceStringFaultType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "error", true, new XmlQualifiedName("s:string")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchemaComplexType      = new XmlSchemaComplexType();
        myXmlSchemaComplexType.Name = "GetTradePriceStringIntType";
        myXmlSchemaSequence         = new XmlSchemaSequence();
        myXmlSchemaSequence.Items.Add(CreateComplexTypeXmlElement("1", "1", "error", true, new XmlQualifiedName("s:int")));
        myXmlSchemaComplexType.Particle = myXmlSchemaSequence;
        myXmlSchema.Items.Add(myXmlSchemaComplexType);

        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapIn", new XmlQualifiedName("s0:GetTradePriceInputType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapOut", new XmlQualifiedName("s0:GetTradePriceOutputType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapStringFault", new XmlQualifiedName("s0:GetTradePriceStringFaultType")));
        myXmlSchema.Items.Add(CreateOtherXmlElement("GetTradePriceSoapIntFault", new XmlQualifiedName("s0:GetTradePriceIntFaultType")));

        myServiceDescription.Types.Schemas.Add(myXmlSchema);

        // Generate the 'Message' element.
        MessageCollection myMessageCollection = myServiceDescription.Messages;

        myMessageCollection.Add(CreateMessage("GetTradePriceInput", "parameters", "GetTradePriceSoapIn", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceOutput", "parameters", "GetTradePriceSoapOut", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceStringFault", "parameters", "GetTradePriceStringSoapFault", myServiceDescription.TargetNamespace));
        myMessageCollection.Add(CreateMessage("GetTradePriceIntFault", "parameters", "GetTradePriceIntSoapFault", myServiceDescription.TargetNamespace));

        // Generate the 'Port Type' element.
        PortTypeCollection myPortTypeCollection = myServiceDescription.PortTypes;
        PortType           myPortType           = new PortType();

        myPortType.Name = "StockQuotePortType";
        OperationCollection myOperationCollection = myPortType.Operations;
        Operation           myOperation           = new Operation();

        myOperation.Name = "GetTradePrice";
        OperationMessage           myOperationMessage;
        OperationMessageCollection myOperationMessageCollection = myOperation.Messages;

        myOperationMessage         = (OperationMessage) new OperationInput();
        myOperationMessage.Message = new XmlQualifiedName("s0:GetTradePriceInput");
        myOperationMessageCollection.Add(myOperationMessage);
        myOperationMessage         = (OperationMessage) new OperationOutput();
        myOperationMessage.Message = new XmlQualifiedName("s0:GetTradePriceOutput");
        myOperationMessageCollection.Add(myOperationMessage);
        OperationFault myOperationFault = new OperationFault();

        myOperationFault.Name    = "ErrorString";
        myOperationFault.Message = new XmlQualifiedName("s0:GetTradePriceStringFault");
        myOperation.Faults.Add(myOperationFault);
        myOperationFault         = new OperationFault();
        myOperationFault.Name    = "ErrorInt";
        myOperationFault.Message = new XmlQualifiedName("s0:GetTradePriceIntFault");
        myOperation.Faults.Add(myOperationFault);
        myOperationCollection.Add(myOperation);
        myPortTypeCollection.Add(myPortType);

        // Generate the 'Binding' element.
        ServiceDescriptionFormatExtensionCollection myExtensions;
        BindingCollection myBindingCollection = myServiceDescription.Bindings;
        Binding           myBinding           = new Binding();

        myBinding.Name = "StockQuoteSoapBinding";
        myBinding.Type = new XmlQualifiedName("s0:StockQuotePortType");
        myExtensions   = myBinding.Extensions;
        SoapBinding mySoapBinding = new SoapBinding();

        mySoapBinding.Style     = SoapBindingStyle.Document;
        mySoapBinding.Transport = "http://schemas.xmlsoap.org/soap/http";
        myExtensions.Add(mySoapBinding);
        OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
        OperationBinding           myOperationBinding           = new OperationBinding();

        myExtensions = myOperationBinding.Extensions;
        SoapOperationBinding mySoapBindingOperation = new SoapOperationBinding();

        mySoapBindingOperation.SoapAction = "http://www.contoso.com/GetTradePrice";
        myExtensions.Add(mySoapBindingOperation);
        myOperationBinding.Name  = "GetTradePrice";
        myOperationBinding.Input = new InputBinding();
        myExtensions             = myOperationBinding.Input.Extensions;
        SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();

        mySoapBodyBinding.Use       = SoapBindingUse.Literal;
        mySoapBodyBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapBodyBinding);
        myOperationBinding.Output = new OutputBinding();
        myExtensions                = myOperationBinding.Output.Extensions;
        mySoapBodyBinding           = new SoapBodyBinding();
        mySoapBodyBinding.Use       = SoapBindingUse.Literal;
        mySoapBodyBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapBodyBinding);
// <Snippet1>
// <Snippet2>
// <Snippet3>
        FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults;
        FaultBinding           myFaultBinding           = new FaultBinding();

        myFaultBinding.Name = "ErrorString";
        // Associate SOAP fault binding to the fault binding of the operation.
        myExtensions = myFaultBinding.Extensions;
        SoapFaultBinding mySoapFaultBinding = new SoapFaultBinding();

        mySoapFaultBinding.Use       = SoapBindingUse.Literal;
        mySoapFaultBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapFaultBinding);
        myFaultBindingCollection.Add(myFaultBinding);
// </Snippet3>
// </Snippet2>
// </Snippet1>
        myFaultBinding      = new FaultBinding();
        myFaultBinding.Name = "ErrorInt";
        // Associate SOAP fault binding to the fault binding of the operation.
        myExtensions                 = myFaultBinding.Extensions;
        mySoapFaultBinding           = new SoapFaultBinding();
        mySoapFaultBinding.Use       = SoapBindingUse.Literal;
        mySoapFaultBinding.Namespace = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapFaultBinding);
        myFaultBindingCollection.Add(myFaultBinding);
        myOperationBindingCollection.Add(myOperationBinding);
        myBindingCollection.Add(myBinding);

        // Generate the 'Service' element.
        ServiceCollection myServiceCollection = myServiceDescription.Services;
// <Snippet4>
        Service myService = new Service();

        // Add a simple documentation for the service to ease the readability of the generated WSDL file.
        myService.Documentation = "A Simple Stock Quote Service";
        myService.Name          = "StockQuoteService";
        PortCollection myPortCollection = myService.Ports;
        Port           myPort           = new Port();

        myPort.Name    = "StockQuotePort";
        myPort.Binding = new XmlQualifiedName("s0:StockQuoteSoapBinding");
        myExtensions   = myPort.Extensions;
        SoapAddressBinding mySoapAddressBinding = new SoapAddressBinding();

        mySoapAddressBinding.Location = "http://www.contoso.com/stockquote";
        myExtensions.Add(mySoapAddressBinding);
        myPortCollection.Add(myPort);
// </Snippet4>
        myServiceCollection.Add(myService);

        // Display the WSDL generated to the console.
        myServiceDescription.Write(Console.Out);
    }
Пример #29
0
    static void Main()
    {
        try
        {
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("MathService_input_cs.wsdl");

            // Add the OperationBinding for the Add operation.
            OperationBinding addOperationBinding = new OperationBinding();
            string           addOperation        = "Add";
            string           myTargetNamespace   = myServiceDescription.TargetNamespace;
            addOperationBinding.Name = addOperation;

            // Add the InputBinding for the operation.
            InputBinding    myInputBinding    = new InputBinding();
            SoapBodyBinding mySoapBodyBinding = new SoapBodyBinding();
            mySoapBodyBinding.Use = SoapBindingUse.Literal;
            myInputBinding.Extensions.Add(mySoapBodyBinding);
            addOperationBinding.Input = myInputBinding;

            // Add the OutputBinding for the operation.
            OutputBinding myOutputBinding = new OutputBinding();
            myOutputBinding.Extensions.Add(mySoapBodyBinding);
            addOperationBinding.Output = myOutputBinding;

            // Add the extensibility element for the SoapOperationBinding.
            SoapOperationBinding mySoapOperationBinding =
                new SoapOperationBinding();
            mySoapOperationBinding.Style      = SoapBindingStyle.Document;
            mySoapOperationBinding.SoapAction = myTargetNamespace + addOperation;
            addOperationBinding.Extensions.Add(mySoapOperationBinding);

            // Get the BindingCollection from the ServiceDescription.
            BindingCollection myBindingCollection =
                myServiceDescription.Bindings;

            // Get the OperationBindingCollection of SOAP binding from
            // the BindingCollection.
            OperationBindingCollection myOperationBindingCollection =
                myBindingCollection[0].Operations;

// <Snippet2>
            // Check for the Add OperationBinding in the collection.
            bool contains = myOperationBindingCollection.Contains
                                (addOperationBinding);
            Console.WriteLine("\nWhether the collection contains the Add " +
                              "OperationBinding : " + contains);
// </Snippet2>

// <Snippet3>
            // Add the Add OperationBinding to the collection.
            myOperationBindingCollection.Add(addOperationBinding);
            Console.WriteLine("\nAdded the OperationBinding of the Add" +
                              " operation to the collection.");
// </Snippet3>

// <Snippet4>
// <Snippet5>
            // Get the OperationBinding of the Add operation from the collection.
            OperationBinding myOperationBinding =
                myOperationBindingCollection[3];

            // Remove the OperationBinding of the Add operation from
            // the collection.
            myOperationBindingCollection.Remove(myOperationBinding);
            Console.WriteLine("\nRemoved the OperationBinding of the " +
                              "Add operation from the collection.");
// </Snippet5>
// </Snippet4>

// <Snippet6>
// <Snippet7>
            // Insert the OperationBinding of the Add operation at index 0.
            myOperationBindingCollection.Insert(0, addOperationBinding);
            Console.WriteLine("\nInserted the OperationBinding of the " +
                              "Add operation in the collection.");

            // Get the index of the OperationBinding of the Add
            // operation from the collection.
            int index = myOperationBindingCollection.IndexOf(addOperationBinding);
            Console.WriteLine("\nThe index of the OperationBinding of the " +
                              "Add operation : " + index);
// </Snippet7>
// </Snippet6>
            Console.WriteLine("");

// <Snippet8>
            OperationBinding[] operationBindingArray = new
                                                       OperationBinding[myOperationBindingCollection.Count];

            // Copy this collection to the OperationBinding array.
            myOperationBindingCollection.CopyTo(operationBindingArray, 0);
            Console.WriteLine("The operations supported by this service " +
                              "are :");
            foreach (OperationBinding myOperationBinding1 in
                     operationBindingArray)
            {
                Binding myBinding = myOperationBinding1.Binding;
                Console.WriteLine(" Binding : " + myBinding.Name + " Name of " +
                                  "operation : " + myOperationBinding1.Name);
            }
// </Snippet8>

            // Save the ServiceDescription to an external file.
            myServiceDescription.Write("MathService_new_cs.wsdl");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
Пример #30
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());
        }