This documentation is archived and is not being maintained.
ServiceDescription.CanRead Method
.NET Framework 1.1
Gets a value indicating whether an XmlReader represents a valid Web Services Description Language (WSDL) file that can be parsed.
[Visual Basic] Public Shared Function CanRead( _ ByVal reader As XmlReader _ ) As Boolean [C#] public static bool CanRead( XmlReader reader ); [C++] public: static bool CanRead( XmlReader* reader ); [JScript] public static function CanRead( reader : XmlReader ) : Boolean;
Parameters
- reader
- An XmlReader
Return Value
true if the XmlSerializer can recognize the node on which the XmlReader is positioned; otherwise false.
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
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: