This documentation is archived and is not being maintained.

ContractReference Class

Represents a reference in a discovery document to a service description.

For a list of all members of this type, see ContractReference Members.

System.Object
   System.Web.Services.Discovery.DiscoveryReference
      System.Web.Services.Discovery.ContractReference

[Visual Basic]
Public Class ContractReference
   Inherits DiscoveryReference
[C#]
public class ContractReference : DiscoveryReference
[C++]
public __gc class ContractReference : public DiscoveryReference
[JScript]
public class ContractReference extends DiscoveryReference

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

XML Web services discovery involves discovering the available Web Services given an URL. The URL usually points to a discovery document, which typically has a .disco file name extension. Within a discovery document are references to information about the existance of XML Web services. These references can refer to service descriptions, XML Schema Definition language (XSD) schemas or other discovery documents. This class represents a reference to a Service Description.

Within a discovery document, a reference to a Service Description is contained within a contractRef XML element. The contractRef XML element has two attributes: ref and docRef. The contractRef element must have an XML namespace matching the Namespace constant, whereas the ref and docRef attributes are placed in the Ref and DocRef properties.

Example

[Visual Basic] 
Imports System
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 'Main
End Class 'MyContractReference

[C#] 
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);
      }
   }
}

[C++] 
#using <mscorlib.dll>
#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 = new DiscoveryDocument();

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

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

      // Set the URL for an XML Web service implementing the service
      // description.
      myContractReference->DocRef = S"http://localhost/service1.asmx";
      SoapBinding* myBinding = new SoapBinding();
      myBinding->Binding = new XmlQualifiedName(S"q1:Service1Soap");
      myBinding->Address = S"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(S"Service1.disco",
         FileMode::OpenOrCreate, FileAccess::Write);
      StreamWriter* myStreamWriter = new StreamWriter(myFileStream);

      // Write myDiscoveryDocument into the passed stream.
      myDiscoveryDocument->Write(myStreamWriter);
      Console::WriteLine(S"The Service1.disco is generated.");
   } catch (Exception* e) {
      Console::WriteLine(S"Error is {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.Services.Discovery

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web.Services (in System.Web.Services.dll)

See Also

ContractReference Members | System.Web.Services.Discovery Namespace | DiscoveryReference | ServiceDescription | SchemaReference | DiscoveryDocumentReference | DiscoveryClientProtocol

Show: