ContractReference 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示探索 (Discovery) 文件中對服務描述的參考。
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
- 繼承
範例
#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 通常會指向探索檔,通常副檔名為 .disco。 探索檔內是 XML Web 服務存在相關資訊的參考。 這些參考可以參考服務描述、XML 架構定義語言 (XSD) 架構或其他探索檔。 這個類別代表服務描述的參考。
在探索檔中,服務描述的參考會包含在 XML 元素內 contractRef
。
contractRef
XML 元素有兩個屬性: ref
和 docRef
。 元素 contractRef
必須具有符合常數的 Namespace XML 命名空間,而 ref
和 docRef
屬性則放在 和 DocRef 屬性中 Ref 。
建構函式
ContractReference() |
使用預設值,初始化 ContractReference 類別的新執行個體。 |
ContractReference(String) |
使用提供的服務描述的參考,初始化 ContractReference 類別的新執行個體。 |
ContractReference(String, String) |
使用提供的服務描述的參考和實作服務描述的 XML Web Service,初始化 ContractReference 類別的新執行個體。 |
欄位
Namespace |
探索文件中的服務描述參考的 XML 命名空間。 |
屬性
ClientProtocol |
取得或設定 DiscoveryClientProtocol 的執行個體,其在探索程序中使用。 (繼承來源 DiscoveryReference) |
Contract |
取得 ServiceDescription 物件,表示服務描述。 |
DefaultFilename |
取得當儲存參考的服務描述時根據預設會使用的檔案名稱。 |
DocRef |
取得或設定 XML Web Service 的 URL,此服務會實作 Ref 屬性中參考的服務描述。 |
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。 |