Exemplo n.º 1
0
    public static void Main()
    {
        try
        {
// <Snippet1>
// <Snippet2>
// <Snippet3>
// <Snippet4>
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("MathService_CS.wsdl");

            PortTypeCollection myPortTypeCollection =
                myServiceDescription.PortTypes;
            int noOfPortTypes = myServiceDescription.PortTypes.Count;
            Console.WriteLine("\nTotal number of PortTypes: " + noOfPortTypes);

            PortType myNewPortType = myPortTypeCollection["MathServiceSoap"];

// </Snippet4>
            // Get the index in the collection.
            int index = myPortTypeCollection.IndexOf(myNewPortType);
// </Snippet3>
            Console.WriteLine("Removing the PortType named "
                              + myNewPortType.Name);

            // Remove the PortType from the collection.
            myPortTypeCollection.Remove(myNewPortType);
            noOfPortTypes = myServiceDescription.PortTypes.Count;
            Console.WriteLine("\nTotal number of PortTypes: "
                              + noOfPortTypes);

            // Check whether the PortType exists in the collection.
            bool bContains = myPortTypeCollection.Contains(myNewPortType);
            Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: "
                              + bContains);

            Console.WriteLine("Adding the PortType");
            // Insert a new portType at the index location.
            myPortTypeCollection.Insert(index, myNewPortType);
// </Snippet2>

            // Display the number of portTypes after adding a port.
            Console.WriteLine("Total number of PortTypes after "
                              + "adding a new port: " + myServiceDescription.PortTypes.Count);

            bContains = myPortTypeCollection.Contains(myNewPortType);
            Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: "
                              + bContains);
            myServiceDescription.Write("MathService_New.wsdl");
// </Snippet1>
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
    public static void Main()
    {
        try
        {
            // Read the existing Web service description file.
            ServiceDescription myServiceDescription =
                ServiceDescription.Read("MathService_CS.wsdl");
            PortTypeCollection myPortTypeCollection =
                myServiceDescription.PortTypes;
            int noOfPortTypes = myServiceDescription.PortTypes.Count;
            Console.WriteLine("\nTotal number of PortTypes: "
                              + myServiceDescription.PortTypes.Count);

            // Get the first PortType in the collection.
            PortType myNewPortType = myPortTypeCollection["MathServiceSoap"];
            int      index         = myPortTypeCollection.IndexOf(myNewPortType);
            Console.WriteLine("The PortType with the name " + myNewPortType.Name
                              + " is at index: " + (index + 1));

            Console.WriteLine("Removing the PortType: " + myNewPortType.Name);

            // Remove the PortType from the collection.
            myPortTypeCollection.Remove(myNewPortType);
            bool bContains = myPortTypeCollection.Contains(myNewPortType);
            Console.WriteLine("The PortType with the name " + myNewPortType.Name
                              + " exists: " + bContains);

            Console.WriteLine("Total number of PortTypes after removing: "
                              + myServiceDescription.PortTypes.Count);

            Console.WriteLine("Adding a PortType: " + myNewPortType.Name);

            // Add a new portType from the collection.
            myPortTypeCollection.Add(myNewPortType);

            // Display the number of portTypes after adding a port.
            Console.WriteLine("Total number of PortTypes after "
                              + "adding a new port: " + myServiceDescription.PortTypes.Count);

            // List the PortTypes available in the WSDL document.
            foreach (PortType myPortType in myPortTypeCollection)
            {
                Console.WriteLine("The PortType name is: " + myPortType.Name);
            }

            myServiceDescription.Write("MathService_New.wsdl");
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }