本文整理汇总了C#中System.Web.Services.Discovery.DiscoveryReference类的典型用法代码示例。如果您正苦于以下问题:C# DiscoveryReference类的具体用法?C# DiscoveryReference怎么用?C# DiscoveryReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DiscoveryReference类属于System.Web.Services.Discovery命名空间,在下文中一共展示了DiscoveryReference类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Web.Services.Discovery;
using System.Net;
class MyDiscoveryDocumentClass
{
static void Main()
{
try {
DiscoveryDocument myDiscoveryDocument;
StreamReader myStreamReader =
new StreamReader("c:\\Inetpub\\wwwroot\\dataservice.disco");
FileStream myStream = new FileStream("c:\\MyDiscovery.disco",
FileMode.OpenOrCreate);
Console.WriteLine("Demonstrating DiscoveryReference class.");
// Read discovery file.
myDiscoveryDocument = DiscoveryDocument.Read(myStreamReader);
// Create a new instance of the DiscoveryReference class.
MyDiscoveryReferenceClass myDiscoveryReference;
myDiscoveryReference = new MyDiscoveryReferenceClass();
DiscoveryClientProtocol myDiscoveryClientProtocol =
new DiscoveryClientProtocol();
myDiscoveryClientProtocol.Credentials =
CredentialCache.DefaultCredentials;
// Set the client protocol.
myDiscoveryReference.ClientProtocol = myDiscoveryClientProtocol;
// Read the default file name.
Console.WriteLine("Default file name is: "
+ myDiscoveryReference.DefaultFilename);
// Write the document.
myDiscoveryReference.WriteDocument(myDiscoveryDocument,myStream);
// Read the document.
myDiscoveryReference.ReadDocument(myStream);
// Set the URL.
myDiscoveryReference.Url = "http://localhost/dataservice.disco";
Console.WriteLine("Url is: " + myDiscoveryReference.Url);
// Resolve the URL.
myDiscoveryReference.Resolve();
myStreamReader.Close();
myStream.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception caught! - {0}", e.Message);
}
}
}
// Class derived from DiscoveryReference class and overriding it members.
class MyDiscoveryReferenceClass : DiscoveryReference
{
private string myDocumentUrl;
public override string DefaultFilename
{
get
{
return "dataservice.disco";
}
}
public override object ReadDocument(Stream stream)
{
return stream;
}
public new void Resolve()
{
try
{
DiscoveryDocument myDiscoveryRefDocument;
myDiscoveryRefDocument = base.ClientProtocol.Discover(Url);
}
catch (Exception e)
{
throw(e);
}
}
protected override void Resolve(string contentType, Stream stream) {}
public override string Url
{
get
{
return myDocumentUrl;
}
set
{
myDocumentUrl = value;
}
}
public override void WriteDocument(object document, System.IO.Stream stream)
{
DiscoveryDocument myDiscoveryDocument = (DiscoveryDocument)document;
myDiscoveryDocument.Write(stream);
}
}