Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

PortType Class

Represents a named set of abstract operations and the corresponding abstract messages. This class cannot be inherited.

Namespace: System.Web.Services.Description
Assembly: System.Web.Services (in system.web.services.dll)
public sealed class PortType : NamedItem
public final class PortType extends NamedItem
public final class PortType extends NamedItem
Not applicable.

The PortType class corresponds to the Web Services Description Language (WSDL) portType element enclosed by the definitions root element. For more information about WSDL, see the specification at http://www.w3.org/TR/wsdl.

using System;
using System.Web.Services.Description;
using System.Xml;

class MyPortTypeClass
{
   public static void Main()
   {
      try
      {
         PortTypeCollection myPortTypeCollection;
         ServiceDescription myServiceDescription =
            ServiceDescription.Read("MathService_CS.wsdl");
         
         myPortTypeCollection = myServiceDescription.PortTypes;
         int noOfPortTypes = myServiceDescription.PortTypes.Count;
         Console.WriteLine("\nTotal number of PortTypes : "
            + noOfPortTypes);

         PortType myPortType = myPortTypeCollection["MathServiceSoap"];
         myPortTypeCollection.Remove(myPortType);

         // Create a new PortType.
         PortType myNewPortType = new PortType();
         myNewPortType.Name = "MathServiceSoap";
         OperationCollection myOperationCollection = 
            myServiceDescription.PortTypes[0].Operations;
         for(int i=0;i<myOperationCollection.Count;i++)
         {
            string inputmsg = myOperationCollection[i].Name + "SoapIn";
            string outputmsg = myOperationCollection[i].Name + "SoapOut";
            Console.WriteLine("Operation = " + myOperationCollection[i].Name);
            myNewPortType.Operations.Add(
               CreateOperation(myOperationCollection[i].Name, inputmsg, 
               outputmsg,myServiceDescription.TargetNamespace));
         }

         // Add the PortType to the collection.
         myPortTypeCollection.Add(myNewPortType);
         noOfPortTypes = myServiceDescription.PortTypes.Count;
         Console.WriteLine("\nTotal Number of PortTypes : " 
            + noOfPortTypes);
         myServiceDescription.Write("MathService_New.wsdl");
      }
      catch(Exception e)
      {
         Console.WriteLine("Exception: " + e.Message);
      }
   }
   public static Operation CreateOperation(string operationName, 
      string inputMessage, string outputMessage, string targetNamespace)
   {
      Operation myOperation = new Operation();
      myOperation.Name = operationName;
      OperationMessage input = (OperationMessage) new OperationInput();
      input.Message = new XmlQualifiedName(inputMessage, targetNamespace);
      OperationMessage output = (OperationMessage) new OperationOutput();
      output.Message = new XmlQualifiedName(outputMessage, targetNamespace);
      myOperation.Messages.Add(input);
      myOperation.Messages.Add(output);
      return myOperation;
   }
}

import System.*;
import System.Web.Services.Description.*; 
import System.Xml.*;

class MyPortTypeClass
{
    public static void main(String[] args)
    {
        try {
            PortTypeCollection myPortTypeCollection;
            ServiceDescription myServiceDescription = ServiceDescription.Read(
                "MathService_JSL.wsdl");

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

            PortType myPortType = myPortTypeCollection.get_Item(
                "MathServiceSoap");
            myPortTypeCollection.Remove(myPortType);

            // Create a new PortType.
            PortType myNewPortType = new PortType();
            myNewPortType.set_Name("MathServiceSoap");
            OperationCollection myOperationCollection = myServiceDescription.
            get_PortTypes().get_Item(0).get_Operations();
            for (int i = 0; i < myOperationCollection.get_Count(); i++) {
                String inputmsg = myOperationCollection.get_Item(i).get_Name() 
                       + "SoapIn";
                String outputmsg = myOperationCollection.get_Item(i).get_Name() 
                       + "SoapOut";
                Console.WriteLine("Operation = " 
                    + myOperationCollection.get_Item(i).get_Name());
                myNewPortType.get_Operations().Add(CreateOperation(
                    myOperationCollection.get_Item(i).get_Name(), inputmsg,
                    outputmsg, myServiceDescription.get_TargetNamespace()));
            }

            // Add the PortType to the collection.
            myPortTypeCollection.Add(myNewPortType);
            noOfPortTypes = myServiceDescription.get_PortTypes().get_Count();
            Console.WriteLine("\nTotal Number of PortTypes : " 
                + noOfPortTypes);
            myServiceDescription.Write("MathService_New.wsdl");
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: " + e.get_Message());
        }
    } //main

    public static Operation CreateOperation(String operationName, 
        String inputMessage, String outputMessage, String targetNamespace)
    {
        Operation myOperation = new Operation();
        myOperation.set_Name(operationName);
        OperationMessage input = (OperationMessage)new OperationInput();
        input.set_Message(new XmlQualifiedName(inputMessage, targetNamespace));
        OperationMessage output = (OperationMessage)new OperationOutput();
        output.set_Message(new XmlQualifiedName(outputMessage, 
            targetNamespace));
        myOperation.get_Messages().Add(input);
        myOperation.get_Messages().Add(output);
        return myOperation;
    } //CreateOperation
} //MyPortTypeClass

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.