Exemple #1
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);
        }
    }
    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);
        }
    }
Exemple #3
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);
    }