This documentation is archived and is not being maintained.

ServiceDescription.PortTypes Property

Gets the collection of PortType elements contained in the ServiceDescription.

[Visual Basic]
Public ReadOnly Property PortTypes As PortTypeCollection
[C#]
public PortTypeCollection PortTypes {get;}
[C++]
public: __property PortTypeCollection* get_PortTypes();
[JScript]
public function get PortTypes() : PortTypeCollection;

Property Value

A PortTypeCollection.

Remarks

The PortTypeCollection returned by this property corresponds to the list of <portType> elements enclosed by the Web Services Description Language (WSDL) <definitions> root element. For more information about WSDL, see the specification at http://www.w3.org/TR/wsdl/.

Example

[Visual Basic] 
Shared Sub Main()
   Dim myWsdlFileName As String = "MyWsdl_VB.wsdl"
   Dim myReader As New XmlTextReader(myWsdlFileName)
   If ServiceDescription.CanRead(myReader) Then
      
      Dim myDescription As ServiceDescription = _
         ServiceDescription.Read(myWsdlFileName)

      ' Remove the PortType at index 0 of the collection.
      Dim myPortTypeCollection As PortTypeCollection = _
         myDescription.PortTypes
      myPortTypeCollection.Remove(myDescription.PortTypes(0))

      ' Build a new PortType.
      Dim myPortType As New PortType()
      myPortType.Name = "Service1Soap"
      Dim myOperation As Operation = _
         CreateOperation("Add", "s0:AddSoapIn", "s0:AddSoapOut", "")
      myPortType.Operations.Add(myOperation)

      ' Add a new PortType to the PortType collection of 
      ' the ServiceDescription.
      myDescription.PortTypes.Add(myPortType)
      
      myDescription.Write("MyOutWsdl.wsdl")
      Console.WriteLine("New WSDL file generated successfully.")
   Else
      Console.WriteLine("This file is not a WSDL file.")
   End If
End Sub 'Main
 
' Creates an Operation for a PortType.
Public Shared Function CreateOperation(operationName As String, _
   inputMessage As String, outputMessage As String, _
   targetNamespace As String) As Operation

   Dim myOperation As New Operation()
   myOperation.Name = operationName
   Dim input As OperationMessage = _
      CType(New OperationInput(), OperationMessage)
   input.Message = New XmlQualifiedName(inputMessage, targetNamespace)
   Dim output As OperationMessage = _
      CType(New OperationOutput(), OperationMessage)
   output.Message = New XmlQualifiedName(outputMessage, targetNamespace)
   myOperation.Messages.Add(input)
   myOperation.Messages.Add(output)
   Return myOperation
End Function 'CreateOperation

[C#] 
static void Main()
{
   string myWsdlFileName ="MyWsdl_CS.wsdl";
   XmlTextReader myReader = new XmlTextReader(myWsdlFileName);
   if (ServiceDescription.CanRead(myReader))
   {
      ServiceDescription myDescription = 
         ServiceDescription.Read(myWsdlFileName);

      // Remove the PortType at index 0 of the collection.
      PortTypeCollection myPortTypeCollection = 
         myDescription.PortTypes;
      myPortTypeCollection.Remove(myDescription.PortTypes[0]);
      
      // Build a new PortType.
      PortType myPortType = new PortType();
      myPortType.Name = "Service1Soap";
      Operation myOperation = 
         CreateOperation("Add","s0:AddSoapIn","s0:AddSoapOut","");
      myPortType.Operations.Add(myOperation);

      // Add a new PortType to the PortType collection of 
      // the ServiceDescription.
      myDescription.PortTypes.Add(myPortType);

      myDescription.Write("MyOutWsdl.wsdl");
      Console.WriteLine("New WSDL file generated successfully.");
   }
   else
   {
      Console.WriteLine("This file is not a WSDL file.");
   }

}
// Creates an Operation for a PortType.
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;
}

[C++] 
// Creates an Operation for a PortType.

Operation* CreateOperation(String* operationName, 
                           String* inputMessage, String* outputMessage, String* targetNamespace)
{
   Operation* myOperation = new Operation();
   myOperation->Name = operationName;
   OperationMessage* input = dynamic_cast<OperationMessage*> (new OperationInput());
   input->Message = new XmlQualifiedName(inputMessage,targetNamespace);
   OperationMessage* output = dynamic_cast<OperationMessage*> (new OperationOutput());
   output->Message = new XmlQualifiedName(outputMessage,targetNamespace);
   myOperation->Messages->Add(input);
   myOperation->Messages->Add(output);
   return myOperation;
}

int main()
{
   String* myWsdlFileName =S"MyWsdl_CS.wsdl";
   XmlTextReader* myReader = new XmlTextReader(myWsdlFileName);
   if (ServiceDescription::CanRead(myReader))
   {
      ServiceDescription* myDescription = 
         ServiceDescription::Read(myWsdlFileName);

      // Remove the PortType at index 0 of the collection.
      PortTypeCollection* myPortTypeCollection = 
         myDescription->PortTypes;
      myPortTypeCollection->Remove(myDescription->PortTypes->Item[0]);

      // Build a new PortType.
      PortType* myPortType = new PortType();
      myPortType->Name = S"Service1Soap";
      Operation* myOperation = 
         CreateOperation(S"Add",S"s0:AddSoapIn",S"s0:AddSoapOut",S"");
      myPortType->Operations->Add(myOperation);

      // Add a new PortType to the PortType collection of 
      // the ServiceDescription.
      myDescription->PortTypes->Add(myPortType);

      myDescription->Write(S"MyOutWsdl.wsdl");
      Console::WriteLine(S"New WSDL file generated successfully.");
   }
   else
   {
      Console::WriteLine(S"This file is not a WSDL file.");
   }

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ServiceDescription Class | ServiceDescription Members | System.Web.Services.Description Namespace

Show: