ContractReference 类

定义

表示发现文档中对服务说明的引用。

public ref class ContractReference : System::Web::Services::Discovery::DiscoveryReference
public class ContractReference : System.Web.Services.Discovery.DiscoveryReference
type ContractReference = class
    inherit DiscoveryReference
Public Class ContractReference
Inherits DiscoveryReference
继承
ContractReference

示例

#using <System.Xml.dll>
#using <System.Web.Services.dll>

using namespace System;
using namespace System::Xml;
using namespace System::IO;
using namespace System::Web::Services::Discovery;
int main()
{
   try
   {
      
      // Get a DiscoveryDocument.
      DiscoveryDocument^ myDiscoveryDocument = gcnew DiscoveryDocument;
      
      // Get a ContractReference.
      ContractReference^ myContractReference = gcnew ContractReference;
      
      // Set the URL to the referenced service description.
      myContractReference->Ref = "http://localhost/service1.asmx?wsdl";
      
      // Set the URL for an XML Web service implementing the service
      // description.
      myContractReference->DocRef = "http://localhost/service1.asmx";
      SoapBinding^ myBinding = gcnew SoapBinding;
      myBinding->Binding = gcnew XmlQualifiedName( "q1:Service1Soap" );
      myBinding->Address = "http://localhost/service1.asmx";
      
      // Add myContractReference to the list of references contained
      // in the discovery document.
      myDiscoveryDocument->References->Add( myContractReference );
      
      // Add Binding to the references collection.
      myDiscoveryDocument->References->Add( myBinding );
      
      // Open or create a file for writing.
      FileStream^ myFileStream = gcnew FileStream( "Service1.disco",FileMode::OpenOrCreate,FileAccess::Write );
      StreamWriter^ myStreamWriter = gcnew StreamWriter( myFileStream );
      
      // Write myDiscoveryDocument into the passed stream.
      myDiscoveryDocument->Write( myStreamWriter );
      Console::WriteLine( "The Service1.disco is generated." );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Error is {0}", e->Message );
   }

}
using System;
using System.Xml;
using System.IO;
using System.Web.Services.Discovery;

public class MyContractReference
{
   static void Main()
   {
      try
      {
         // Get a DiscoveryDocument.
         DiscoveryDocument myDiscoveryDocument = new  DiscoveryDocument();

         // Get a ContractReference.
         ContractReference myContractReference = new ContractReference();

         // Set the URL to the referenced service description.
         myContractReference.Ref = "http://localhost/service1.asmx?wsdl";

         // Set the URL for an XML Web service implementing the service
         // description.
         myContractReference.DocRef = "http://localhost/service1.asmx";
         SoapBinding myBinding = new SoapBinding();
         myBinding.Binding = new XmlQualifiedName("q1:Service1Soap");
         myBinding.Address = "http://localhost/service1.asmx";

         // Add myContractReference to the list of references contained
         // in the discovery document.
         myDiscoveryDocument.References.Add(myContractReference);

         // Add Binding to the references collection.
         myDiscoveryDocument.References.Add(myBinding);

         // Open or create a file for writing.
         FileStream myFileStream = new FileStream("Service1.disco",
             FileMode.OpenOrCreate, FileAccess.Write );
         StreamWriter myStreamWriter = new StreamWriter( myFileStream );

         // Write myDiscoveryDocument into the passed stream.
         myDiscoveryDocument.Write( myStreamWriter );
         Console.WriteLine("The Service1.disco is generated.");
      }
      catch(Exception e)
      {
         Console.WriteLine("Error is "+ e.Message);
      }
   }
}
Imports System.Xml
Imports System.IO
Imports System.Web.Services.Discovery

Public Class MyContractReference
   Shared Sub Main()
      Try
         ' Get a 'DiscoveryDocument' object.
         Dim myDiscoveryDocument As New DiscoveryDocument()
         ' Get a 'ContractReference' object.
         Dim myContractReference As New ContractReference()
         ' Set the URL to the referenced service description.
         myContractReference.Ref = "http://localhost/service1.asmx?wsdl"
         ' Set the URL for a XML Web service implementing the service
         ' description .
         myContractReference.DocRef = "http://localhost/service1.asmx"
         Dim myBinding As New SoapBinding()
         myBinding.Binding = New XmlQualifiedName("q1:Service1Soap")
         myBinding.Address = "http://localhost/service1.asmx"
         ' Add 'myContractReference' to the list of references contained 
         ' within the discovery document.
         myDiscoveryDocument.References.Add(myContractReference)
         ' Add 'Binding' to referenceCollection.
         myDiscoveryDocument.References.Add(myBinding)
         ' Open or create a file for writing .
         Dim myFileStream As New FileStream("Service1.disco", FileMode.OpenOrCreate, FileAccess.Write)
         Dim myStreamWriter As New StreamWriter(myFileStream)
         ' Write 'myDiscoveryDocument' into the passed stream.
         myDiscoveryDocument.Write(myStreamWriter)
         Console.WriteLine("The 'Service1.disco' is generated.")
      Catch e As Exception
         Console.WriteLine("Error is" + e.Message)
      End Try
   End Sub
End Class

注解

XML Web 服务发现涉及发现给定 URL 的可用 Web 服务。 URL 通常指向发现文档,该文档通常具有 a.disco 文件扩展名。 在发现文档中,引用了有关 XML Web 服务存在的信息。 这些引用可以引用服务说明、XML 架构定义语言 (XSD) 架构或其他发现文档。 此类表示对服务说明的引用。

在发现文档中,对服务说明的引用包含在 XML 元素中 contractRefcontractRef XML 元素有两个属性: refdocRef。 元素contractRef必须具有与 常量匹配的 Namespace XML 命名空间,而 refdocRef 属性位于 和 DocRef 属性中Ref

构造函数

ContractReference()

使用默认值初始化 ContractReference 类的新实例。

ContractReference(String)

使用所提供的对服务说明的引用初始化 ContractReference 类的新实例。

ContractReference(String, String)

使用所提供的对某个服务说明和实现此服务说明的 XML Web services 的引用初始化 ContractReference 类的新实例。

字段

Namespace

发现文档中的服务说明引用的 XML 命名空间。

属性

ClientProtocol

获取或设置在发现过程中使用的 DiscoveryClientProtocol 的实例。

(继承自 DiscoveryReference)
Contract

获取一个表示服务说明的 ServiceDescription 对象。

DefaultFilename

获取默认情况下保存引用的服务说明时所使用的文件的名称。

DocRef

获取或设置实现在 Ref 属性中引用的服务说明的 XML Web services 的 URL。

Ref

获取或设置所引用的服务说明的 URL。

Url

获取或设置所引用的服务说明的 URL。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ReadDocument(Stream)

从传递的 Stream 读取服务说明并返回此服务说明。

Resolve()

下载 Url 处的引用文档以解析引用的文档是否有效。

(继承自 DiscoveryReference)
Resolve(String, Stream)

解析引用的文档是否有效。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
WriteDocument(Object, Stream)

将传入的服务说明写入传入的 Stream

适用于

另请参阅