public static void Main()
    {
        // Read the 'StockQuote.wsdl' file as input.
        ServiceDescription myServiceDescription = ServiceDescription.Read("StockQuote.wsdl");

        // Get the operation fault collection and remove the operation fault with the name 'ErrorString'.
        PortTypeCollection       myPortTypeCollection       = myServiceDescription.PortTypes;
        PortType                 myPortType                 = myPortTypeCollection[0];
        OperationCollection      myOperationCollection      = myPortType.Operations;
        Operation                myOperation                = myOperationCollection[0];
        OperationFaultCollection myOperationFaultCollection = myOperation.Faults;

        if (myOperationFaultCollection.Contains(myOperationFaultCollection["ErrorString"]))
        {
            myOperationFaultCollection.Remove(myOperationFaultCollection["ErrorString"]);
        }

        // Get the fault binding collection and remove the fault binding with the name 'ErrorString'.
// <Snippet1>
        BindingCollection          myBindingCollection          = myServiceDescription.Bindings;
        Binding                    myBinding                    = myBindingCollection[0];
        OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
        OperationBinding           myOperationBinding           = myOperationBindingCollection[0];
        FaultBindingCollection     myFaultBindingCollection     = myOperationBinding.Faults;

        if (myFaultBindingCollection.Contains(myFaultBindingCollection["ErrorString"]))
        {
            myFaultBindingCollection.Remove(myFaultBindingCollection["ErrorString"]);
        }
// </Snippet1>

        myServiceDescription.Write(Console.Out);
    }
        /// <summary>
        /// Retrive methods from the wsdl file.
        /// </summary>
        /// <param name="url"></param>
        private void getMethods(String url)
        {
            try
            {
                //Get Service Description and all the required methods.
                ServiceDescription         sd         = getServiceDescription(url);
                OperationBindingCollection operations = sd.Bindings[0].Operations;
                tblButtons.Controls.Clear();
                TableRow tRow = new TableRow();

                tRow.Attributes.Add("style", "margin:15px;");

                ddlMethods.DataSource    = operations;
                ddlMethods.DataTextField = "Name";
                ddlMethods.DataBind();

                Session["methods"] = operations;

                //cprExtender.Collapsed = false;
                //ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "hello", "showMethods();", true);

                pnlMethods.Visible = true;
            }
            catch (Exception)
            {
                throw;
            }
        }
    public static void Main()
    {
        try
        {
            // Read the 'StockQuote.wsdl' file as input.
            ServiceDescription myServiceDescription = ServiceDescription.
                                                      Read("StockQuote_cs.wsdl");
            // Remove the operation fault with the name 'ErrorString'.
            PortTypeCollection myPortTypeCollection = myServiceDescription.
                                                      PortTypes;
            PortType            myPortType            = myPortTypeCollection[0];
            OperationCollection myOperationCollection = myPortType.Operations;
            Operation           myOperation           = myOperationCollection[0];

// <Snippet1>
            OperationFaultCollection myOperationFaultCollection =
                myOperation.Faults;
            OperationFault myOperationFault =
                myOperationFaultCollection["ErrorString"];
            if (myOperationFault != null)
            {
                myOperationFaultCollection.Remove(myOperationFault);
            }
// </Snippet1>

            // Remove the fault binding with the name 'ErrorString'.
            BindingCollection myBindingCollection = myServiceDescription.
                                                    Bindings;
            Binding myBinding = myBindingCollection[0];
            OperationBindingCollection myOperationBindingCollection =
                myBinding.Operations;
            OperationBinding myOperationBinding =
                myOperationBindingCollection[0];
            FaultBindingCollection myFaultBindingCollection =
                myOperationBinding.Faults;
            if (myFaultBindingCollection.Contains(
                    myFaultBindingCollection["ErrorString"]))
            {
                myFaultBindingCollection.Remove(
                    myFaultBindingCollection["ErrorString"]);
            }

            myServiceDescription.Write("OperationFaultCollection_out.wsdl");
            Console.WriteLine("WSDL file with name 'OperationFaultCollection_out.wsdl'" +
                              " created Successfully");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
        static void Main()
        {
// <Snippet2>
            ServiceDescription myServicDescription =
                ServiceDescription.Read("MimeMultiPartRelatedSample_cs.wsdl");

            // Get the binding collection.
            BindingCollection myBindingCollection = myServicDescription.Bindings;
            int index = 0;

            for (int i = 0; i < myBindingCollection.Count; i++)
            {
                // Get the collection for MimeServiceHttpPost.
                if (myBindingCollection[i].Name == "MimeServiceHttpPost")
                {
                    OperationBindingCollection myOperationBindingCollection =
                        myBindingCollection[i].Operations;
                    OutputBinding myOutputBinding =
                        myOperationBindingCollection[0].Output;
                    ServiceDescriptionFormatExtensionCollection
                        myServiceDescriptionFormatExtensionCollection =
                        myOutputBinding.Extensions;
                    MimeMultipartRelatedBinding myMimeMultipartRelatedBinding =
                        (MimeMultipartRelatedBinding)
                        myServiceDescriptionFormatExtensionCollection.Find(
                            typeof(MimeMultipartRelatedBinding));
                    MimePartCollection myMimePartCollection =
                        myMimeMultipartRelatedBinding.Parts;
                    foreach (MimePart myMimePart in myMimePartCollection)
                    {
                        Console.WriteLine("Extension types added to MimePart: " +
                                          index++);
                        Console.WriteLine("----------------------------");
                        foreach (object myExtension in myMimePart.Extensions)
                        {
                            Console.WriteLine(myExtension.GetType());
                        }
                        Console.WriteLine();
                    }
                    break;
                }
            }
// </Snippet2>
        }
Beispiel #5
0
    public static void Main()
    {
// <Snippet1>
        // Read the 'Operation_Faults_Input_CS.wsdl' file as input.
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("Operation_Faults_Input_CS.wsdl");

        // Get the operation fault collection.
        PortTypeCollection  myPortTypeCollection  = myServiceDescription.PortTypes;
        PortType            myPortType            = myPortTypeCollection[0];
        OperationCollection myOperationCollection = myPortType.Operations;

        // Remove the operation fault with the name 'ErrorString'.
        Operation myOperation = myOperationCollection[0];
        OperationFaultCollection myOperationFaultCollection = myOperation.Faults;

        if (myOperationFaultCollection.Contains(myOperationFaultCollection["ErrorString"]))
        {
            myOperationFaultCollection.Remove(myOperationFaultCollection["ErrorString"]);
        }
// </Snippet1>

        // Get the fault binding collection.
        BindingCollection          myBindingCollection          = myServiceDescription.Bindings;
        Binding                    myBinding                    = myBindingCollection[0];
        OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
        // Remove the fault binding with the name 'ErrorString'.
        OperationBinding       myOperationBinding       = myOperationBindingCollection[0];
        FaultBindingCollection myFaultBindingCollection = myOperationBinding.Faults;

        if (myFaultBindingCollection.Contains(myFaultBindingCollection["ErrorString"]))
        {
            myFaultBindingCollection.Remove(myFaultBindingCollection["ErrorString"]);
        }

        myServiceDescription.Write("Operation_Faults_Output_CS.wsdl");
        Console.WriteLine("WSDL file with name 'Operation_Faults_Output_CS.wsdl' file created Successfully");
    }
    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);
        }
    }
    public static void Main()
    {
        // Read the 'StockQuote.wsdl' file as input.
        ServiceDescription myServiceDescription = ServiceDescription.Read("StockQuote.wsdl");

        PortTypeCollection       myPortTypeCollection       = myServiceDescription.PortTypes;
        PortType                 myPortType                 = myPortTypeCollection[0];
        OperationCollection      myOperationCollection      = myPortType.Operations;
        Operation                myOperation                = myOperationCollection[0];
        OperationFaultCollection myOperationFaultCollection = myOperation.Faults;

        // Reverse the operation fault order.
        if (myOperationFaultCollection.Count > 1)
        {
            OperationFault[] myOperationFaultArray = new OperationFault[myOperationFaultCollection.Count];
            // Copy the operation fault to a temporary array.
            myOperationFaultCollection.CopyTo(myOperationFaultArray, 0);
            // Remove all the operation fault instances in the fault binding collection.
            for (int i = 0; i < myOperationFaultArray.Length; i++)
            {
                myOperationFaultCollection.Remove(myOperationFaultArray[i]);
            }
            // Insert the operation fault instance in the reverse order.
            for (int i = 0, j = (myOperationFaultArray.Length - 1); i < myOperationFaultArray.Length; i++, j--)
            {
                myOperationFaultCollection.Insert(i, myOperationFaultArray[j]);
            }
        }

// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
// <Snippet5>
// <Snippet6>

        BindingCollection          myBindingCollection          = myServiceDescription.Bindings;
        Binding                    myBinding                    = myBindingCollection[0];
        OperationBindingCollection myOperationBindingCollection = myBinding.Operations;
        OperationBinding           myOperationBinding           = myOperationBindingCollection[0];
        FaultBindingCollection     myFaultBindingCollection     = myOperationBinding.Faults;

        // Reverse the fault bindings order.
        if (myFaultBindingCollection.Count > 1)
        {
            FaultBinding myFaultBinding = myFaultBindingCollection[0];

            FaultBinding[] myFaultBindingArray = new FaultBinding[myFaultBindingCollection.Count];
            // Copy the fault bindings to a temporary array.
            myFaultBindingCollection.CopyTo(myFaultBindingArray, 0);

            // Remove all the fault binding instances in the fault binding collection.
            for (int i = 0; i < myFaultBindingArray.Length; i++)
            {
                myFaultBindingCollection.Remove(myFaultBindingArray[i]);
            }

            // Insert the fault binding instance in the reverse order.
            for (int i = 0, j = (myFaultBindingArray.Length - 1); i < myFaultBindingArray.Length; i++, j--)
            {
                myFaultBindingCollection.Insert(i, myFaultBindingArray[j]);
            }
            // Check if the first element in the collection before the reversal is now the last element.
            if (myFaultBindingCollection.Contains(myFaultBinding) &&
                myFaultBindingCollection.IndexOf(myFaultBinding) == (myFaultBindingCollection.Count - 1))
            {
                // Display the WSDL generated to the console.
                myServiceDescription.Write(Console.Out);
            }
            else
            {
                Console.WriteLine("Error while reversing");
            }
        }

// </Snippet6>
// </Snippet5>
// </Snippet4>
// </Snippet3>
// </Snippet2>
// </Snippet1>
    }
    public static void Main()
    {
        try
        {
            // Read the StockQuote.wsdl file as input.
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("StockQuote_cs.wsdl");
// <Snippet2>
// <Snippet3>
// <Snippet4>
// <Snippet5>
// <Snippet6>
// <Snippet7>
            PortTypeCollection myPortTypeCollection =
                myServiceDescription.PortTypes;
            PortType                 myPortType                 = myPortTypeCollection[0];
            OperationCollection      myOperationCollection      = myPortType.Operations;
            Operation                myOperation                = myOperationCollection[0];
            OperationFaultCollection myOperationFaultCollection =
                myOperation.Faults;

            // Reverse the operation fault order.
            if (myOperationFaultCollection.Count > 1)
            {
                OperationFault   myOperationFault      = myOperationFaultCollection[0];
                OperationFault[] myOperationFaultArray =
                    new OperationFault[myOperationFaultCollection.Count];

                // Copy the operation faults to a temporary array.
                myOperationFaultCollection.CopyTo(myOperationFaultArray, 0);

                // Remove all the operation faults from the collection.
                for (int i = 0; i < myOperationFaultArray.Length; i++)
                {
                    myOperationFaultCollection.Remove(myOperationFaultArray[i]);
                }

                // Insert the operation faults in the reverse order.
                for (int i = 0, j = (myOperationFaultArray.Length - 1);
                     i < myOperationFaultArray.Length; i++, j--)
                {
                    myOperationFaultCollection.Insert(
                        i, myOperationFaultArray[j]);
                }
                if (myOperationFaultCollection.Contains(myOperationFault) &&
                    (myOperationFaultCollection.IndexOf(myOperationFault)
                     == myOperationFaultCollection.Count - 1))
                {
                    Console.WriteLine(
                        "Succeeded in reversing the operation faults.");
                }
                else
                {
                    Console.WriteLine("Error while reversing the faults.");
                }
            }
// </Snippet7>
// </Snippet6>
// </Snippet5>
// </Snippet4>
// </Snippet3>
// </Snippet2>
            BindingCollection myBindingCollection =
                myServiceDescription.Bindings;
            Binding myBinding = myBindingCollection[0];
            OperationBindingCollection myOperationBindingCollection =
                myBinding.Operations;
            OperationBinding myOperationBinding =
                myOperationBindingCollection[0];
            FaultBindingCollection myFaultBindingCollection =
                myOperationBinding.Faults;

            // Reverse the fault binding order.
            if (myFaultBindingCollection.Count > 1)
            {
                FaultBinding myFaultBinding = myFaultBindingCollection[0];

                FaultBinding[] myFaultBindingArray =
                    new FaultBinding[myFaultBindingCollection.Count];

                // Copy the fault bindings to a temporary array.
                myFaultBindingCollection.CopyTo(myFaultBindingArray, 0);

                // Remove all the fault bindings.
                for (int i = 0; i < myFaultBindingArray.Length; i++)
                {
                    myFaultBindingCollection.Remove(myFaultBindingArray[i]);
                }

                // Insert the fault bindings in the reverse order.
                for (int i = 0, j = (myFaultBindingArray.Length - 1);
                     i < myFaultBindingArray.Length; i++, j--)
                {
                    myFaultBindingCollection.Insert(i, myFaultBindingArray[j]);
                }

                // Check whether the first element before the reversal
                // is now the last element.
                if (myFaultBindingCollection.Contains(myFaultBinding) &&
                    myFaultBindingCollection.IndexOf(myFaultBinding) ==
                    (myFaultBindingCollection.Count - 1))
                {
                    // Write the WSDL generated to a file.
                    myServiceDescription.Write("StockQuoteOut_cs.wsdl");
                    Console.WriteLine(
                        "The file StockQuoteOut_cs.wsdl was successfully written.");
                }
                else
                {
                    Console.WriteLine(
                        "An error occurred while reversing the input WSDL file.");
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
Beispiel #9
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);
        }
    }
Beispiel #10
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);
    }
Beispiel #11
0
        public List <string> GenerateProxyAssembly(string uri)
        {
            //create a WebRequest object and fetch the WSDL file for the web service
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            System.IO.Stream stream = response.GetResponseStream();

            //read the downloaded WSDL file
            ServiceDescription desc = ServiceDescription.Read(stream);


            //find out the number of operations exposed by the web service
            //store the name of the operations inside the string array
            //iterating only through the first binding exposed as
            //the rest of the bindings will have the same number
            int     i       = 0;
            Binding binding = desc.Bindings[0];
            OperationBindingCollection opColl = binding.Operations;
            //string[] listOfOperations = new string[opColl.Count];
            List <string> listOfOperations = new List <string>();

            foreach (OperationBinding operation in opColl)
            {
                // Console.WriteLine(operation.Name);
                //   listOfOperations[i++] = operation.Name;
                listOfOperations.Add(operation.Name);
            }

            //initializing a ServiceDescriptionImporter object
            ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

            //set the protocol to SOAP 1.1
            importer.ProtocolName = "Soap12";

            //setting the Style to Client in order to generate client proxy code
            importer.Style = ServiceDescriptionImportStyle.Client;

            //adding the ServiceDescription to the Importer object
            importer.AddServiceDescription(desc, null, null);
            importer.CodeGenerationOptions = CodeGenerationOptions.GenerateNewAsync;

            //Initialize the CODE DOM tree in which we will import the
            //ServiceDescriptionImporter
            CodeNamespace   nm   = new CodeNamespace();
            CodeCompileUnit unit = new CodeCompileUnit();

            unit.Namespaces.Add(nm);

            //generating the client proxy code
            ServiceDescriptionImportWarnings warnings = importer.Import(nm, unit);

            if (warnings == 0)
            {
                //set the CodeDOMProvider to C# to generate the code in C#
                System.IO.StringWriter sw       = new System.IO.StringWriter();
                CodeDomProvider        provider = CodeDomProvider.CreateProvider("C#");
                provider.GenerateCodeFromCompileUnit(unit, sw, new CodeGeneratorOptions());

                //creating TempFileCollection
                //the path of the temp folder is hardcoded
                TempFileCollection coll = new TempFileCollection(@"C:\wmpub\tempFiles");
                coll.KeepFiles = false;

                //setting the CompilerParameters for the temporary assembly
                string[]           refAssembly = { "System.dll", "System.Data.dll", "System.Web.Services.dll", "System.Xml.dll" };
                CompilerParameters param       = new CompilerParameters(refAssembly);
                param.GenerateInMemory      = true;
                param.TreatWarningsAsErrors = false;
                param.OutputAssembly        = "WebServiceReflector.dll";
                param.TempFiles             = coll;

                //compile the generated code into an assembly
                //CompilerResults results = provider.CompileAssemblyFromDom(param, unitArr);
                CompilerResults results = provider.CompileAssemblyFromSource(param, sw.ToString());
                this.Assembly = results.CompiledAssembly;
            }

            //return the list of operations exposed by the web service
            return(listOfOperations);
        }