Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

ContractReference Class

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

Namespace: System.Web.Services.Discovery
Assembly: System.Web.Services (in system.web.services.dll)
public class ContractReference : DiscoveryReference
public class ContractReference extends DiscoveryReference
public class ContractReference extends DiscoveryReference
Not applicable.

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.

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);
      }
   }
}

import System.*;
import System.Xml.*;
import System.IO.*;
import System.Web.Services.Discovery.*;

public class MyContractReference
{
    public static void main(String[] args)
    {
        try {
            // Get a DiscoveryDocument.
            DiscoveryDocument myDiscoveryDocument = new DiscoveryDocument();

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

            // Set the URL to the referenced service description.
            myContractReference.set_Ref("http://localhost/service1.asmx?wsdl");

            // Set the URL for an XML Web service implementing the service
            // description.
            myContractReference.set_DocRef("http://localhost/service1.asmx");

            SoapBinding myBinding = new SoapBinding();

            myBinding.set_Binding(new XmlQualifiedName("q1:Service1Soap"));
            myBinding.set_Address("http://localhost/service1.asmx");

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

            // Add Binding to the references collection.
            myDiscoveryDocument.get_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 (System.Exception e) {
            Console.WriteLine("Error is " + e.get_Message());
        }
    } //main
} //MyContractReference

System.Object
   System.Web.Services.Discovery.DiscoveryReference
    System.Web.Services.Discovery.ContractReference
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.