示例#1
0
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("MimeXmlBinding_Part_3_Input_CS.wsdl");
            // Create the 'Binding' object.
            Binding myBinding = new Binding();
            // Initialize 'Name' property of 'Binding' class.
            myBinding.Name = "MimeXmlBinding_Part_3_ServiceHttpPost";
            XmlQualifiedName
                myXmlQualifiedName = new XmlQualifiedName("s0:MimeXmlBinding_Part_3_ServiceHttpPost");
            myBinding.Type = myXmlQualifiedName;
            // Create the 'HttpBinding' object.
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            // Add the 'HttpBinding' to the 'Binding'.
            myBinding.Extensions.Add(myHttpBinding);
            // Create the 'OperationBinding' object.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myHttpOperationBinding = new HttpOperationBinding();
            myHttpOperationBinding.Location = "/AddNumbers";
            // Add the 'HttpOperationBinding' to 'OperationBinding'.
            myOperationBinding.Extensions.Add(myHttpOperationBinding);
            // Create the 'InputBinding' object.
            InputBinding       myInputBinding       = new InputBinding();
            MimeContentBinding myMimeContentBinding = new MimeContentBinding();
            myMimeContentBinding.Type = "application/x-www-form-urlencoded";
            myInputBinding.Extensions.Add(myMimeContentBinding);
            // Add the 'InputBinding' to 'OperationBinding'.
            myOperationBinding.Input = myInputBinding;
            // Create an OutputBinding.
            OutputBinding  myOutputBinding  = new OutputBinding();
            MimeXmlBinding myMimeXmlBinding = new MimeXmlBinding();

            // Initialize the Part property of the MimeXmlBinding.
            myMimeXmlBinding.Part = "Body";

            // Add the MimeXmlBinding to the OutputBinding.
            myOutputBinding.Extensions.Add(myMimeXmlBinding);
            // Add the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutputBinding;
            // 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("MimeXmlBinding_Part_3_Output_CS.wsdl");
            Console.WriteLine("WSDL file with name 'MimeXmlBinding_Part_3_Output_CS.wsdl' is"
                              + " created successfully.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: {0}", e.Message);
        }
    }
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("MimePartCollection_1_Input_cs.wsdl");
        ServiceDescriptionCollection myServiceDescriptionCol =
            new ServiceDescriptionCollection();

        myServiceDescriptionCol.Add(myServiceDescription);
        XmlQualifiedName myXmlQualifiedName =
            new  XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/");
        // Create a 'Binding' object.
        Binding          myBinding          = myServiceDescriptionCol.GetBinding(myXmlQualifiedName);
        OperationBinding myOperationBinding = null;

        for (int i = 0; i < myBinding.Operations.Count; i++)
        {
            if (myBinding.Operations[i].Name.Equals("AddNumbers"))
            {
                myOperationBinding = myBinding.Operations[i];
            }
        }
        OutputBinding myOutputBinding = myOperationBinding.Output;
        MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null;
        IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator();

        while (myIEnumerator.MoveNext())
        {
            myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding)myIEnumerator.Current;
        }
        // Create an instances of 'MimePartCollection'.
        MimePartCollection myMimePartCollection = new MimePartCollection();

        myMimePartCollection = myMimeMultipartRelatedBinding.Parts;

        Console.WriteLine("Total number of mimepart elements initially is: "
                          + myMimePartCollection.Count);
        // Create an instance of 'MimePart'.
        MimePart myMimePart = new MimePart();
        // Create an instance of 'MimeXmlBinding'.
        MimeXmlBinding myMimeXmlBinding = new MimeXmlBinding();

        myMimeXmlBinding.Part = "body";
        myMimePart.Extensions.Add(myMimeXmlBinding);
        // Insert a mimepart at first position.
        myMimePartCollection.Insert(0, myMimePart);
        Console.WriteLine("Inserting a mimepart object...");
        if (myMimePartCollection.Contains(myMimePart))
        {
            Console.WriteLine("'MimePart' is succesffully added at position: "
                              + myMimePartCollection.IndexOf(myMimePart));
            Console.WriteLine("Total number of mimepart elements after inserting is: "
                              + myMimePartCollection.Count);
        }
        myServiceDescription.Write("MimePartCollection_1_Output_CS.wsdl");
        Console.WriteLine("MimePartCollection_1_Output_CS.wsdl has been generated successfully.");
    }
示例#3
0
        public string GenerateHttpGetMessage(Port port, OperationBinding obin, Operation oper, OperationMessage msg)
        {
            string req = "";

            if (msg is OperationInput)
            {
                HttpAddressBinding   sab = port.Extensions.Find(typeof(HttpAddressBinding)) as HttpAddressBinding;
                HttpOperationBinding sob = obin.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                string location          = new Uri(sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString(msg);
                req += "GET " + location + "\n";
                req += "Host: " + GetLiteral("string");
            }
            else
            {
                req += "HTTP/1.0 200 OK\n";
                req += "Content-Type: text/xml; charset=utf-8\n";
                req += "Content-Length: " + GetLiteral("string") + "\n\n";

                MimeXmlBinding mxb = (MimeXmlBinding)obin.Output.Extensions.Find(typeof(MimeXmlBinding)) as MimeXmlBinding;
                if (mxb == null)
                {
                    return(req);
                }

                Message          message = descriptions.GetMessage(msg.Message);
                XmlQualifiedName ename   = null;
                foreach (MessagePart part in message.Parts)
                {
                    if (part.Name == mxb.Part)
                    {
                        ename = part.Element;
                    }
                }

                if (ename == null)
                {
                    return(req + GetLiteral("string"));
                }

                StringWriter  sw  = new StringWriter();
                XmlTextWriter xtw = new XmlTextWriter(sw);
                xtw.Formatting = Formatting.Indented;
                currentUse     = SoapBindingUse.Literal;
                WriteRootElementSample(xtw, ename);
                xtw.Close();
                req += sw.ToString();
            }

            return(req);
        }
示例#4
0
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("MimePart_3_Input_cs.wsdl");
        ServiceDescriptionCollection myServiceDescriptionCol =
            new ServiceDescriptionCollection();

        myServiceDescriptionCol.Add(myServiceDescription);
        XmlQualifiedName myXmlQualifiedName =
            new XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/");

        // Create the Binding.
        Binding myBinding =
            myServiceDescriptionCol.GetBinding(myXmlQualifiedName);
        OperationBinding myOperationBinding = null;

        for (int i = 0; i < myBinding.Operations.Count; i++)
        {
            if (myBinding.Operations[i].Name.Equals("AddNumbers"))
            {
                myOperationBinding = myBinding.Operations[i];
            }
        }
// <Snippet2>
// <Snippet3>
        // Create the OutputBinding.
        OutputBinding  myOutputBinding  = myOperationBinding.Output;
        MimeXmlBinding myMimeXmlBinding = new MimeXmlBinding();

        myMimeXmlBinding.Part = "body";

        // Create the MimePart.
        MimePart myMimePart = new MimePart();

        myMimePart.Extensions.Add(myMimeXmlBinding);
        MimeMultipartRelatedBinding myMimePartRelatedBinding =
            new MimeMultipartRelatedBinding();

        // Add the MimePart to the MimePartRelatedBinding.
        myMimePartRelatedBinding.Parts.Add(myMimePart);
        myOutputBinding.Extensions.Add(myMimePartRelatedBinding);
// </Snippet3>
// </Snippet2>
        myServiceDescription.Write("MimePart_3_Output_CS.wsdl");
        Console.WriteLine(
            "MimePart_3_Output_CS.wsdl has been generated successfully.");
    }
示例#5
0
    public static void Main()
    {
        ServiceDescription myDescription = ServiceDescription.Read("AddNumbers1.wsdl");

        // Create the 'Binding' object.
        Binding myBinding = new Binding();

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

        myBinding.Type = qualifiedName;

// <Snippet1>
// <Snippet2>

        // Create the 'HttpBinding' object.
        HttpBinding myHttpBinding = new HttpBinding();

        myHttpBinding.Verb = "POST";
        // Add the 'HttpBinding' to the 'Binding'.
        myBinding.Extensions.Add(myHttpBinding);
// </Snippet2>
// </Snippet1>

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

        myOperationBinding.Name = "AddNumbers";

        HttpOperationBinding myOperation = new HttpOperationBinding();

        myOperation.Location = "/AddNumbers";
        // Add the 'HttpOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(myOperation);

        // Create the 'InputBinding' object.
        InputBinding       myInput = new InputBinding();
        MimeContentBinding postMimeContentbinding = new MimeContentBinding();

        postMimeContentbinding.Type = "application/x-www-form-urlencoded";
        myInput.Extensions.Add(postMimeContentbinding);
        // Add the 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInput;
        // Create the 'OutputBinding' object.
        OutputBinding  myOutput           = new OutputBinding();
        MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();

        postMimeXmlbinding.Part = "Body";
        myOutput.Extensions.Add(postMimeXmlbinding);

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

        // Create  a 'Port' object.
        Port postPort = new Port();

        postPort.Name    = "Service1HttpPost";
        postPort.Binding = new XmlQualifiedName("s0:Service1HttpPost");

// <Snippet3>
// <Snippet4>

        // Create the 'HttpAddressBinding' object.
        HttpAddressBinding postAddressBinding = new HttpAddressBinding();

        postAddressBinding.Location = "http://localhost/Service1.asmx";

        // Add the 'HttpAddressBinding' to the 'Port'.
        postPort.Extensions.Add(postAddressBinding);
// </Snippet4>
// </Snippet3>

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

        // Create a 'PortType' object.
        PortType postPortType = new PortType();

        postPortType.Name = "Service1HttpPost";

        Operation postOperation = new Operation();

        postOperation.Name = "AddNumbers";

        OperationMessage postInput = (OperationMessage) new OperationInput();

        postInput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostIn");
        OperationMessage postOutput = (OperationMessage) new OperationOutput();

        postOutput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostOut");

        postOperation.Messages.Add(postInput);
        postOperation.Messages.Add(postOutput);

        // Add the 'Operation' to 'PortType'.
        postPortType.Operations.Add(postOperation);

        // Adds the 'PortType' to 'PortTypeCollection' of 'ServiceDescription'.
        myDescription.PortTypes.Add(postPortType);

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

        postMessage1.Name = "AddNumbersHttpPostIn";
        // Create the 'MessageParts'.
        MessagePart postMessagePart1 = new MessagePart();

        postMessagePart1.Name = "firstnumber";
        postMessagePart1.Type = new XmlQualifiedName("s:string");

        MessagePart postMessagePart2 = new MessagePart();

        postMessagePart2.Name = "secondnumber";
        postMessagePart2.Type = new XmlQualifiedName("s:string");
        // Add the 'MessagePart' objects to 'Messages'.
        postMessage1.Parts.Add(postMessagePart1);
        postMessage1.Parts.Add(postMessagePart2);

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

        postMessage2.Name = "AddNumbersHttpPostOut";

        MessagePart postMessagePart3 = new MessagePart();

        postMessagePart3.Name    = "Body";
        postMessagePart3.Element = new XmlQualifiedName("s0:int");
        // Add the 'MessagePart' to 'Message'
        postMessage2.Parts.Add(postMessagePart3);

        // Add the 'Message' objects to 'ServiceDescription'.
        myDescription.Messages.Add(postMessage1);
        myDescription.Messages.Add(postMessage2);

        // Write the 'ServiceDescription' as a WSDL file.
        myDescription.Write("AddNumbers.wsdl");
        Console.WriteLine("WSDL file with name 'AddNumber.Wsdl' file created Successfully");
    }
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("AddNumbersIn_cs.wsdl");

            // Add the ServiceHttpPost binding.
            Binding myBinding = new Binding();
            myBinding.Name = "ServiceHttpPost";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:ServiceHttpPost");
            myBinding.Type = myXmlQualifiedName;
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            myBinding.Extensions.Add(myHttpBinding);

            // Add the operation name AddNumbers.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myOperation = new HttpOperationBinding();
            myOperation.Location = "/AddNumbers";
            myOperationBinding.Extensions.Add(myOperation);

            // Add the input binding.
            InputBinding       myInput = new InputBinding();
            MimeContentBinding postMimeContentbinding =
                new MimeContentBinding();
            postMimeContentbinding.Type = "application/x-www-form-urlencoded";
            myInput.Extensions.Add(postMimeContentbinding);

            // Add the InputBinding to the OperationBinding.
            myOperationBinding.Input = myInput;

            // Add the ouput binding.
            OutputBinding  myOutput           = new OutputBinding();
            MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();
            postMimeXmlbinding.Part = "Body";
            myOutput.Extensions.Add(postMimeXmlbinding);

            // Add the OutPutBinding to the OperationBinding.
            myOperationBinding.Output = myOutput;

            myBinding.Operations.Add(myOperationBinding);
            myDescription.Bindings.Add(myBinding);

            // Add the port definition.
            Port postPort = new Port();
            postPort.Name    = "ServiceHttpPost";
            postPort.Binding = new XmlQualifiedName("s0:ServiceHttpPost");
            HttpAddressBinding postAddressBinding = new HttpAddressBinding();
            postAddressBinding.Location = "http://localhost/Service_cs.asmx";
            postPort.Extensions.Add(postAddressBinding);
            myDescription.Services[0].Ports.Add(postPort);

            // Add the post port type definition.
            PortType postPortType = new PortType();
            postPortType.Name = "ServiceHttpPost";
            Operation postOperation = new Operation();
            postOperation.Name = "AddNumbers";
            OperationMessage postInput =
                (OperationMessage) new OperationInput();
            postInput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostIn");
// <Snippet2>
            OperationOutput postOutput = new OperationOutput();
            postOutput.Message =
                new XmlQualifiedName("s0:AddNumbersHttpPostOut");

            postOperation.Messages.Add(postInput);
            postOperation.Messages.Add(postOutput);
            postPortType.Operations.Add(postOperation);
// </Snippet2>
            myDescription.PortTypes.Add(postPortType);

            // Add the first message information.
            Message postMessage1 = new Message();
            postMessage1.Name = "AddNumbersHttpPostIn";
            MessagePart postMessagePart1 = new MessagePart();
            postMessagePart1.Name = "firstnumber";
            postMessagePart1.Type = new XmlQualifiedName("s:string");

            // Add the second message information.
            MessagePart postMessagePart2 = new MessagePart();
            postMessagePart2.Name = "secondnumber";
            postMessagePart2.Type = new XmlQualifiedName("s:string");
            postMessage1.Parts.Add(postMessagePart1);
            postMessage1.Parts.Add(postMessagePart2);
            Message postMessage2 = new Message();
            postMessage2.Name = "AddNumbersHttpPostOut";

            // Add the third message information.
            MessagePart postMessagePart3 = new MessagePart();
            postMessagePart3.Name    = "Body";
            postMessagePart3.Element = new XmlQualifiedName("s0:int");
            postMessage2.Parts.Add(postMessagePart3);

            myDescription.Messages.Add(postMessage1);
            myDescription.Messages.Add(postMessage2);

            // Write the ServiceDescription as a WSDL file.
            myDescription.Write("AddNumbersOut_cs.wsdl");
            Console.WriteLine("WSDL file named AddNumbersOut_cs.Wsdl" +
                              " created successfully.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception caught!!!");
            Console.WriteLine("Source : " + e.Source);
            Console.WriteLine("Message : " + e.Message);
        }
    }
示例#7
0
    public static void Main()
    {
        ServiceDescription myServiceDescription = ServiceDescription.Read("Operation_IsBoundBy_Input_CS.wsdl");
        // Create the 'Binding' object.
        Binding myBinding = new Binding();

        myBinding.Name = "MyOperationIsBoundByServiceHttpPost";
        XmlQualifiedName myXmlQualifiedName = new XmlQualifiedName("s0:OperationServiceHttpPost");

        myBinding.Type = myXmlQualifiedName;
        // Create the 'HttpBinding' object.
        HttpBinding myHttpBinding = new HttpBinding();

        myHttpBinding.Verb = "POST";
        // Add the 'HttpBinding' to the 'Binding'.
        myBinding.Extensions.Add(myHttpBinding);
        // Create the 'OperationBinding' object.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";

        HttpOperationBinding myHttpOperationBinding = new HttpOperationBinding();

        myHttpOperationBinding.Location = "/AddNumbers";
        // Add the 'HttpOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(myHttpOperationBinding);

        // Create the 'InputBinding' object.
        InputBinding       myInputBinding           = new InputBinding();
        MimeContentBinding myPostMimeContentBinding = new MimeContentBinding();

        myPostMimeContentBinding.Type = "application/x-www-form-urlencoded";
        myInputBinding.Extensions.Add(myPostMimeContentBinding);
        // Add the 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInputBinding;
        // Create the 'OutputBinding' object.
        OutputBinding  myOutputBinding      = new OutputBinding();
        MimeXmlBinding myPostMimeXmlBinding = new MimeXmlBinding();

        myPostMimeXmlBinding.Part = "Body";
        myOutputBinding.Extensions.Add(myPostMimeXmlBinding);

        // Add the 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutputBinding;

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

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

        // Create a 'PortType' object.
        PortType myPostPortType = new PortType();

        myPostPortType.Name = "OperationServiceHttpPost";
// <Snippet1>
        Operation myPostOperation = new Operation();

        myPostOperation.Name = myOperationBinding.Name;
        Console.WriteLine("'Operation' instance uses 'OperationBinding': "
                          + myPostOperation.IsBoundBy(myOperationBinding));
// </Snippet1>
        OperationMessage myOperationMessage = (OperationMessage) new OperationInput();

        myOperationMessage.Message = new XmlQualifiedName("s0:AddNumbersHttpPostIn");
        OperationMessage myOperationMessage1 = (OperationMessage) new OperationOutput();

        myOperationMessage1.Message = new XmlQualifiedName("s0:AddNumbersHttpPostOut");

        myPostOperation.Messages.Add(myOperationMessage);
        myPostOperation.Messages.Add(myOperationMessage1);

        // Add the 'Operation' to 'PortType'.
        myPostPortType.Operations.Add(myPostOperation);

        // Adds the 'PortType' to 'PortTypeCollection' of 'ServiceDescription'.
        myServiceDescription.PortTypes.Add(myPostPortType);

        // Write the 'ServiceDescription' as a WSDL file.
        myServiceDescription.Write("Operation_IsBoundBy_Output_CS.wsdl");
        Console.WriteLine("WSDL file with name 'Operation_IsBoundBy_Output_CS.wsdl' created Successfully");
    }
示例#8
0
    public static void Main()
    {
        ServiceDescription myServiceDescription =
            ServiceDescription.Read("MimePartCollection_8_Input_cs.wsdl");
        ServiceDescriptionCollection myServiceDescriptionCol =
            new ServiceDescriptionCollection();

        myServiceDescriptionCol.Add(myServiceDescription);
        XmlQualifiedName myXmlQualifiedName =
            new  XmlQualifiedName("MimeServiceHttpPost", "http://tempuri.org/");
        // Create a binding object.
        Binding          myBinding          = myServiceDescriptionCol.GetBinding(myXmlQualifiedName);
        OperationBinding myOperationBinding = null;

        for (int i = 0; i < myBinding.Operations.Count; i++)
        {
            if (myBinding.Operations[i].Name.Equals("AddNumbers"))
            {
                myOperationBinding = myBinding.Operations[i];
            }
        }
        OutputBinding myOutputBinding = myOperationBinding.Output;
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
        MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null;
        IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator();

        while (myIEnumerator.MoveNext())
        {
            myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding)myIEnumerator.Current;
        }
        // Create an instance of 'MimePartCollection'.
        MimePartCollection myMimePartCollection = new MimePartCollection();

        myMimePartCollection = myMimeMultipartRelatedBinding.Parts;
        Console.WriteLine("Total number of mimepart elements in the collection initially" +
                          " is: " + myMimePartCollection.Count);
        // Get the type of first 'Item' in collection.
        Console.WriteLine("The first object in collection is of type: "
                          + myMimePartCollection[0].ToString());
        MimePart myMimePart1 = new MimePart();
        // Create an instance of 'MimeXmlBinding'.
        MimeXmlBinding myMimeXmlBinding1 = new MimeXmlBinding();

        myMimeXmlBinding1.Part = "body";
        myMimePart1.Extensions.Add(myMimeXmlBinding1);
        //  a mimepart at first position.
        myMimePartCollection.Insert(0, myMimePart1);
        Console.WriteLine("Inserting a mimepart object...");
        // Check whether 'Insert' was successful or not.
        if (myMimePartCollection.Contains(myMimePart1))
        {
            // Display the index of inserted 'MimePart'.
            Console.WriteLine("'MimePart' is succesfully inserted at position: "
                              + myMimePartCollection.IndexOf(myMimePart1));
        }
// </Snippet4>
// </Snippet3>
// </Snippet2>
// </Snippet1>
        Console.WriteLine("Total number of mimepart elements after inserting is: "
                          + myMimePartCollection.Count);

// <Snippet5>
// <Snippet6>
        MimePart       myMimePart2       = new MimePart();
        MimeXmlBinding myMimeXmlBinding2 = new MimeXmlBinding();

        myMimeXmlBinding2.Part = "body";
        myMimePart2.Extensions.Add(myMimeXmlBinding2);
        // Add a mimepart to the mimepartcollection.
        myMimePartCollection.Add(myMimePart2);
        Console.WriteLine("Adding a mimepart object...");
        // Check if collection contains added mimepart object.
        if (myMimePartCollection.Contains(myMimePart2))
        {
            Console.WriteLine("'MimePart' is succesfully added at position: "
                              + myMimePartCollection.IndexOf(myMimePart2));
        }
// </Snippet6>
// </Snippet5>
        Console.WriteLine("Total number of mimepart elements after adding is: "
                          + myMimePartCollection.Count);

// <Snippet7>
        MimePart[] myArray = new MimePart[myMimePartCollection.Count];
        // Copy the mimepartcollection to an array.
        myMimePartCollection.CopyTo(myArray, 0);
        Console.WriteLine("Displaying the array copied from mimepartcollection");
        for (int j = 0; j < myMimePartCollection.Count; j++)
        {
            Console.WriteLine("Mimepart object at position : " + j);
            for (int i = 0; i < myArray[j].Extensions.Count; i++)
            {
                MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray[j].Extensions[i];
                Console.WriteLine("Part: " + (myMimeXmlBinding3.Part));
            }
        }
// </Snippet7>
// <Snippet8>
        Console.WriteLine("Removing a mimepart object...");
        // Remove the mimepart from the mimepartcollection.
        myMimePartCollection.Remove(myMimePart1);
        // Check whether the mimepart is removed or not.
        if (!myMimePartCollection.Contains(myMimePart1))
        {
            Console.WriteLine("Mimepart is succesfully removed from mimepartcollection");
        }
// </Snippet8>
        Console.WriteLine("Total number of elements in collection after removing is: "
                          + myMimePartCollection.Count);
        MimePart[] myArray1 = new MimePart[myMimePartCollection.Count];
        myMimePartCollection.CopyTo(myArray1, 0);
        Console.WriteLine("Dispalying the 'MimePartCollection' after removing");
        for (int j = 0; j < myMimePartCollection.Count; j++)
        {
            Console.WriteLine("Mimepart object at position :" + j);
            for (int i = 0; i < myArray1[j].Extensions.Count; i++)
            {
                MimeXmlBinding myMimeXmlBinding3 = (MimeXmlBinding)myArray1[j].Extensions[i];
                Console.WriteLine("part:  " + (myMimeXmlBinding3.Part));
            }
        }
        myServiceDescription.Write("MimePartCollection_8_output.wsdl");
        Console.WriteLine("MimePartCollection_8_output.wsdl has been generated successfully.");
    }
示例#9
0
    public static void Main()
    {
        try
        {
            ServiceDescription myDescription =
                ServiceDescription.Read("Operation_2_Input_CS.wsdl");
            Binding myBinding = new Binding();
            myBinding.Name = "Operation_2_ServiceHttpPost";
            XmlQualifiedName myQualifiedName =
                new XmlQualifiedName("s0:Operation_2_ServiceHttpPost");
            myBinding.Type = myQualifiedName;
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            // Add the 'HttpBinding' to the 'Binding'.
            myBinding.Extensions.Add(myHttpBinding);
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myHttpOperationBinding = new HttpOperationBinding();
            myHttpOperationBinding.Location = "/AddNumbers";
            // Add the 'HttpOperationBinding' to 'OperationBinding'.
            myOperationBinding.Extensions.Add(myHttpOperationBinding);
            InputBinding       myInputBinding           = new InputBinding();
            MimeContentBinding myPostMimeContentbinding = new MimeContentBinding();
            myPostMimeContentbinding.Type = "application/x-www-form-urlencoded";
            myInputBinding.Extensions.Add(myPostMimeContentbinding);
            // Add the 'InputBinding' to 'OperationBinding'.
            myOperationBinding.Input = myInputBinding;
            OutputBinding  myOutputBinding      = new OutputBinding();
            MimeXmlBinding myPostMimeXmlbinding = new MimeXmlBinding();
            myPostMimeXmlbinding.Part = "Body";
            myOutputBinding.Extensions.Add(myPostMimeXmlbinding);
            // Add the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutputBinding;
            // Add the 'OperationBinding' to 'Binding'.
            myBinding.Operations.Add(myOperationBinding);
            // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
            myDescription.Bindings.Add(myBinding);
            Port myPostPort = new Port();
            myPostPort.Name    = "Operation_2_ServiceHttpPost";
            myPostPort.Binding = new XmlQualifiedName("s0:Operation_2_ServiceHttpPost");
            HttpAddressBinding myPostAddressBinding = new HttpAddressBinding();
            myPostAddressBinding.Location =
                "http://localhost/Operation_2/Operation_2_Service.cs.asmx";
            // Add the 'HttpAddressBinding' to the 'Port'.
            myPostPort.Extensions.Add(myPostAddressBinding);
            // Add the 'Port' to 'PortCollection' of 'ServiceDescription'.
            myDescription.Services[0].Ports.Add(myPostPort);
            PortType myPostPortType = new PortType();
            myPostPortType.Name = "Operation_2_ServiceHttpPost";
            Operation myPostOperation = new Operation();
            myPostOperation.Name = "AddNumbers";
            OperationMessage myPostOperationInput = (OperationMessage) new OperationInput();
            myPostOperationInput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostIn");
            OperationMessage myPostOperationOutput = (OperationMessage) new OperationOutput();
            myPostOperationOutput.Message = new XmlQualifiedName("s0:AddNumbersHttpPostout");
            myPostOperation.Messages.Add(myPostOperationInput);
            myPostOperation.Messages.Add(myPostOperationOutput);
            // Add the 'Operation' to 'PortType'.
            myPostPortType.Operations.Add(myPostOperation);
            // Adds the 'PortType' to 'PortTypeCollection' of 'ServiceDescription'.
            myDescription.PortTypes.Add(myPostPortType);
            Message myPostMessage1 = new Message();
            myPostMessage1.Name = "AddNumbersHttpPostIn";
            MessagePart myPostMessagePart1 = new MessagePart();
            myPostMessagePart1.Name = "firstnumber";
            myPostMessagePart1.Type = new XmlQualifiedName("s:string");
            MessagePart myPostMessagePart2 = new MessagePart();
            myPostMessagePart2.Name = "secondnumber";
            myPostMessagePart2.Type = new XmlQualifiedName("s:string");
            // Add the 'MessagePart' objects to 'Messages'.
            myPostMessage1.Parts.Add(myPostMessagePart1);
            myPostMessage1.Parts.Add(myPostMessagePart2);
            Message myPostMessage2 = new Message();
            myPostMessage2.Name = "AddNumbersHttpPostout";
            MessagePart myPostMessagePart3 = new MessagePart();
            myPostMessagePart3.Name    = "Body";
            myPostMessagePart3.Element = new XmlQualifiedName("s0:int");
            // Add the 'MessagePart' to 'Message'.
            myPostMessage2.Parts.Add(myPostMessagePart3);
            // Add the 'Message' objects to 'ServiceDescription'.
            myDescription.Messages.Add(myPostMessage1);
            myDescription.Messages.Add(myPostMessage2);
            // Write the 'ServiceDescription' as a WSDL file.
            myDescription.Write("Operation_2_Output_CS.wsdl");
            Console.WriteLine(" 'Operation_2_Output_CS.wsdl' file created Successfully");
// <Snippet1>
// <Snippet2>
            string    myString    = null;
            Operation myOperation = new Operation();
            myDescription = ServiceDescription.Read("Operation_2_Input_CS.wsdl");
            Message[] myMessage = new Message[myDescription.Messages.Count];

            // Copy the messages from the service description.
            myDescription.Messages.CopyTo(myMessage, 0);
            for (int i = 0; i < myDescription.Messages.Count; i++)
            {
                MessagePart[] myMessagePart =
                    new MessagePart[myMessage[i].Parts.Count];

                // Copy the message parts into a MessagePart.
                myMessage[i].Parts.CopyTo(myMessagePart, 0);
                for (int j = 0; j < myMessage[i].Parts.Count; j++)
                {
                    myString += myMessagePart[j].Name;
                    myString += " ";
                }
            }
            // Set the ParameterOrderString equal to the list of
            // message part names.
            myOperation.ParameterOrderString = myString;
            string[] myString1 = myOperation.ParameterOrder;
            int      k         = 0;
            Console.WriteLine("The list of message part names is as follows:");
            while (k < 5)
            {
                Console.WriteLine(myString1[k]);
                k++;
            }
// </Snippet2>
// </Snippet1>
        }
        catch (Exception e)
        {
            Console.WriteLine("The following Exception is raised : " + e.Message);
        }
    }
示例#10
0
    public static void Main()
    {
        ServiceDescription myDescription = ServiceDescription.Read("HttpBinding_ctor_Input_CS.wsdl");
// <Snippet1>
// <Snippet2>
        // Create 'Binding' object.
        Binding myBinding = new Binding();

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

        myBinding.Type = qualifiedName;
        // Create 'HttpBinding' object.
        HttpBinding myHttpBinding = new HttpBinding();

        myHttpBinding.Verb = "POST";
        Console.WriteLine("HttpBinding Namespace : " + HttpBinding.Namespace);
// </Snippet2>
        // Add 'HttpBinding' to 'Binding'.
        myBinding.Extensions.Add(myHttpBinding);
// </Snippet1>
        // Create 'OperationBinding' object.
        OperationBinding myOperationBinding = new OperationBinding();

        myOperationBinding.Name = "AddNumbers";
        HttpOperationBinding myOperation = new HttpOperationBinding();

        myOperation.Location = "/AddNumbers";
        // Add 'HttpOperationBinding' to 'OperationBinding'.
        myOperationBinding.Extensions.Add(myOperation);
        // Create 'InputBinding' object.
        InputBinding       myInput = new InputBinding();
        MimeContentBinding postMimeContentbinding = new MimeContentBinding();

        postMimeContentbinding.Type = "application/x-www-form-urlencoded";
        myInput.Extensions.Add(postMimeContentbinding);
        // Add 'InputBinding' to 'OperationBinding'.
        myOperationBinding.Input = myInput;
        // Create 'OutputBinding' object.
        OutputBinding  myOutput           = new OutputBinding();
        MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();

        postMimeXmlbinding.Part = "Body";
        myOutput.Extensions.Add(postMimeXmlbinding);
        // Add 'OutPutBinding' to 'OperationBinding'.
        myOperationBinding.Output = myOutput;
        // Add 'OperationBinding' to 'Binding'.
        myBinding.Operations.Add(myOperationBinding);
        // Add 'Binding' to 'BindingCollection' of 'ServiceDescription'.
        myDescription.Bindings.Add(myBinding);
// <Snippet3>
        // Create a 'Port' object.
        Port postPort = new Port();

        postPort.Name    = "MyHttpBindingServiceHttpPost";
        postPort.Binding = new XmlQualifiedName("s0:MyHttpBindingServiceHttpPost");
        // Create 'HttpAddressBinding' object.
        HttpAddressBinding postAddressBinding = new HttpAddressBinding();

        postAddressBinding.Location = "http://localhost/HttpBinding_ctor/HttpBinding_ctor_Service.cs.asmx";
        // Add 'HttpAddressBinding' to 'Port'.
        postPort.Extensions.Add(postAddressBinding);
// </Snippet3>
        // Add 'Port' to 'PortCollection' of 'ServiceDescription'.
        myDescription.Services[0].Ports.Add(postPort);
        // Write 'ServiceDescription' as a WSDL file.
        myDescription.Write("HttpBinding_ctor_Output_CS.wsdl");
        Console.WriteLine("WSDL file with name 'HttpBinding_ctor_Output_CS.wsdl' file created Successfully");
    }
示例#11
0
    public static void Main()
    {
        try
        {
            int myInt = 0;
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("MimeTextMatch_5_Input_CS.wsdl");
            // Create the 'Binding' object.
            Binding myBinding = new Binding();
            // Initialize 'Name' property of 'Binding' class.
            myBinding.Name = "MimeTextMatchServiceHttpPost";
            XmlQualifiedName myXmlQualifiedName =
                new XmlQualifiedName("s0:MimeTextMatchServiceHttpPost");
            myBinding.Type = myXmlQualifiedName;
            // Create the 'HttpBinding' object.
            HttpBinding myHttpBinding = new HttpBinding();
            myHttpBinding.Verb = "POST";
            // Add the 'HttpBinding' to the 'Binding'.
            myBinding.Extensions.Add(myHttpBinding);
            // Create the 'OperationBinding' object.
            OperationBinding myOperationBinding = new OperationBinding();
            myOperationBinding.Name = "AddNumbers";
            HttpOperationBinding myHttpOperationBinding = new HttpOperationBinding();
            myHttpOperationBinding.Location = "/AddNumbers";
            // Add the 'HttpOperationBinding' object to 'OperationBinding'.
            myOperationBinding.Extensions.Add(myHttpOperationBinding);
// <Snippet5>
// <Snippet4>
// <Snippet3>
// <Snippet2>
            // Create an InputBinding.
            InputBinding            myInputBinding             = new InputBinding();
            MimeTextBinding         myMimeTextBinding          = new MimeTextBinding();
            MimeTextMatchCollection myMimeTextMatchCollection1 =
                new MimeTextMatchCollection();
            MimeTextMatch[] myMimeTextMatch = new MimeTextMatch[3];
            myMimeTextMatchCollection1 = myMimeTextBinding.Matches;

            // Intialize the MimeTextMatch.
            for (myInt = 0; myInt < 3; myInt++)
            {
                // Get a new MimeTextMatch.
                myMimeTextMatch[myInt] = new MimeTextMatch();

                // Assign values to properties of the MimeTextMatch.
                myMimeTextMatch[myInt].Name       = "Title" + Convert.ToString(myInt);
                myMimeTextMatch[myInt].Type       = "*/*";
                myMimeTextMatch[myInt].Pattern    = "TITLE&gt;(.*?)&lt;";
                myMimeTextMatch[myInt].IgnoreCase = true;
                myMimeTextMatch[myInt].Capture    = 2;
                myMimeTextMatch[myInt].Group      = 2;
                if (myInt != 0)
                {
                    // Assign the Repeats property if the index is not 0.
                    myMimeTextMatch[myInt].Repeats = 2;
                }
                else
                {
                    // Assign the RepeatsString property if the index is 0.
                    myMimeTextMatch[myInt].RepeatsString = "4";
                }
                // Add the MimeTextMatch to the collection.
                myMimeTextMatchCollection1.Add(myMimeTextMatch[myInt]);
            }
// </Snippet2>
// </Snippet3>
// </Snippet4>
// </Snippet5>
            myInputBinding.Extensions.Add(myMimeTextBinding);
            // Add the 'InputBinding' to 'OperationBinding'.
            myOperationBinding.Input = myInputBinding;
            // Create the 'OutputBinding' instance.
            OutputBinding  myOutput           = new OutputBinding();
            MimeXmlBinding postMimeXmlbinding = new MimeXmlBinding();
            // Initialize 'Part' property of 'MimeXmlBinding' class.
            postMimeXmlbinding.Part = "Body";
            // Add 'MimeXmlBinding' instance to 'OutputBinding' instance.
            myOutput.Extensions.Add(postMimeXmlbinding);
            // Add the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutput;
            // Add the 'OutPutBinding' to 'OperationBinding'.
            myOperationBinding.Output = myOutput;
            // Add the 'OperationBinding' to 'Binding'.
            myBinding.Operations.Add(myOperationBinding);
            // Add the 'Binding' to 'BindingCollection' of 'ServiceDescription'.
            myServiceDescription.Bindings.Add(myBinding);
            // Write the 'ServiceDescription' as a WSDL file.
            myServiceDescription.Write("MimeTextMatch_5_Output_CS.wsdl");
            Console.WriteLine("WSDL file with name 'MimeTextMatch_5_Output_CS.wsdl' is"
                              + " created successfully.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: {0}", e.Message);
        }
    }