代码段:实现 StreamAccessor

上次修改时间: 2010年4月19日

适用范围: SharePoint Server 2010

本文内容
.NET 连接程序集的示例
ASP.NET Web 服务的示例
WCF 服务的示例

下面的代码示例演示如何在 .NET 连接程序集和 Web 服务中实现 StreamAccessor 方法实例。

.NET 连接程序集的示例

public System.IO.Stream GetOrderReceipt(String id)
{
    return System.Reflection.Assembly.GetExecutingAssembly().
        GetManifestResourceStream("NetShim.SampleFile.txt");
}

ASP.NET Web 服务的示例

[WebMethod]
public System.IO.Stream GetOrderReceipt(String id)
{
    return new System.IO.FileStream(
        Server.MapPath("SampleFile.txt"), System.IO.FileMode.Open);
}

WCF 服务的示例

下面的示例演示服务约定接口中的操作定义。

[OperationContract]
System.IO.Stream GetOrderReceipt(string id);

下面的示例演示方法实例的实现。

public System.IO.Stream GetOrderReceipt(String id)
{
    return new System.IO.FileStream(
        System.Web.Hosting.HostingEnvironment.MapPath(
        "SampleFile.txt"), System.IO.FileMode.Open);
}

请参阅

概念

实现 StreamAccessor