次の方法で共有


ServiceDescription.CanRead メソッド

XmlReader が、解析できる有効な Web サービス記述言語 (WSDL) ファイルを表すかどうかを示す値を取得します。

Public Shared Function CanRead( _
   ByVal reader As XmlReader _) As Boolean
[C#]
public static bool CanRead(XmlReaderreader);
[C++]
public: static bool CanRead(XmlReader* reader);
[JScript]
public static function CanRead(
   reader : XmlReader) : Boolean;

パラメータ

戻り値

XmlReader が配置されているノードを XmlSerializer で認識できる場合は true 。それ以外の場合は false

使用例

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ServiceDescription クラス | ServiceDescription メンバ | System.Web.Services.Description 名前空間