ServiceDescription::PortTypes Property
Gets the collection of PortType elements contained in the ServiceDescription.
Assembly: System.Web.Services (in System.Web.Services.dll)
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/.
// Creates an Operation for a PortType. Operation^ CreateOperation( String^ operationName, String^ inputMessage, String^ outputMessage, String^ targetNamespace ) { Operation^ myOperation = gcnew Operation; myOperation->Name = operationName; OperationMessage^ input = dynamic_cast<OperationMessage^>(gcnew OperationInput); input->Message = gcnew XmlQualifiedName( inputMessage,targetNamespace ); OperationMessage^ output = dynamic_cast<OperationMessage^>(gcnew OperationOutput); output->Message = gcnew XmlQualifiedName( outputMessage,targetNamespace ); myOperation->Messages->Add( input ); myOperation->Messages->Add( output ); return myOperation; } int main() { String^ myWsdlFileName = "MyWsdl_CS.wsdl"; XmlTextReader^ myReader = gcnew 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 = gcnew 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.
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.");
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.