示例#1
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);
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
        SoapHeaderBinding mySoapHeaderBinding = new SoapHeaderBinding();

        // Set the Message within the XML Web service to which the
        // 'SoapHeaderBinding' applies.
        mySoapHeaderBinding.Message =
            new XmlQualifiedName("s0:HelloMyHeader");
        mySoapHeaderBinding.Part = "MyHeader";
        mySoapHeaderBinding.Use  = SoapBindingUse.Literal;
        // Add mySoapHeaderBinding to the 'myInputBinding' object.
        myInputBinding.Extensions.Add(mySoapHeaderBinding);
// </Snippet4>
// </Snippet3>
// </Snippet2>
// </Snippet1>
        // 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'.");
    }
示例#2
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());
        }
示例#3
0
        public override void ExportEndpoint(ServiceEndpoint endpoint)
        {
            List <IWsdlExportExtension> extensions = ExportContractInternal(endpoint.Contract);

            //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);

            foreach (IWsdlExportExtension extn in extensions)
            {
                extn.ExportEndpoint(this, endpoint_context);
            }
        }
示例#4
0
    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 ServiceDescripition 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);
        }
    }
    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'");
    }
示例#6
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");
    }
            /// <summary>
            /// Creates a <see cref="SoapDocumentMethodAttribute"/> or a <see cref="SoapRpcMethodAttribute"/>
            /// that should be applied to proxy method.
            /// </summary>
            private static CustomAttributeBuilder CreateSoapMethodAttribute(Operation operation,
                                                                            OperationBinding operationBinding, SoapOperationBinding soapOperationBinding,
                                                                            XmlMembersMapping inputMembersMapping, XmlMembersMapping outputMembersMapping)
            {
                ReflectionUtils.CustomAttributeBuilderBuilder cabb;

#if !NET_2_0
                // Access XmlMembersMapping.ElementName and .Namespace property using reflection [SPRNET-520]
                string inputMembersMappingElementName = XmlMembersMapping_ElementName.GetValue(inputMembersMapping, null) as string;
                string inputMembersMappingNamespace   = XmlMembersMapping_Namespace.GetValue(inputMembersMapping, null) as string;
#else
                string inputMembersMappingElementName = inputMembersMapping.ElementName;
                string inputMembersMappingNamespace   = inputMembersMapping.Namespace;
#endif

                if (soapOperationBinding.Style == SoapBindingStyle.Rpc)
                {
                    cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(SoapRpcMethodAttribute));
                }
                else
                {
                    cabb = new ReflectionUtils.CustomAttributeBuilderBuilder(typeof(SoapDocumentMethodAttribute));
                    cabb.AddPropertyValue("ParameterStyle", SoapParameterStyle.Wrapped);
                }

                cabb.AddContructorArgument(soapOperationBinding.SoapAction);

#if NET_2_0
                cabb.AddPropertyValue("Use", SoapBindingUse.Literal);
#else
                if (soapOperationBinding.Style != SoapBindingStyle.Rpc)
                {
                    cabb.AddPropertyValue("Use", SoapBindingUse.Literal);
                }
#endif

                if (inputMembersMappingElementName.Length > 0 &&
                    inputMembersMappingElementName != operation.Name)
                {
                    cabb.AddPropertyValue("RequestElementName", inputMembersMappingElementName);
                }

                if (inputMembersMappingNamespace != null)
                {
                    cabb.AddPropertyValue("RequestNamespace", inputMembersMappingNamespace);
                }

                if (outputMembersMapping == null)
                {
                    cabb.AddPropertyValue("OneWay", true);
                }
                else
                {
#if !NET_2_0
                    // Access XmlMembersMapping.ElementName and .Namespace property using reflection [SPRNET-520]
                    string outputMembersMappingElementName = XmlMembersMapping_ElementName.GetValue(outputMembersMapping, null) as string;
                    string outputMembersMappingNamespace   = XmlMembersMapping_Namespace.GetValue(outputMembersMapping, null) as string;
#else
                    string outputMembersMappingElementName = outputMembersMapping.ElementName;
                    string outputMembersMappingNamespace   = outputMembersMapping.Namespace;
#endif
                    if (outputMembersMappingElementName.Length > 0 &&
                        outputMembersMappingElementName != (operation.Name + "Response"))
                    {
                        cabb.AddPropertyValue("ResponseElementName", outputMembersMappingElementName);
                    }

                    if (outputMembersMappingNamespace != null)
                    {
                        cabb.AddPropertyValue("ResponseNamespace", outputMembersMappingNamespace);
                    }
                }

                return(cabb.Build());
            }
示例#8
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");
    }
示例#9
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);
        }
示例#10
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);
        }
    }
示例#11
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);
        }
    }
示例#12
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");
    }
示例#13
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);
    }
示例#14
0
 public void InitializeSoapOperationBinding()
 {
     sob = new SoapOperationBinding();
 }