다음을 통해 공유


Code Snippet: Implementing a StreamAccessor

Applies to: SharePoint Server 2010

In this article
Example for a .NET Connectivity Assembly
Example for an ASP.NET Web Service
Example for a WCF Service

The following code examples show how you can implement a StreamAccessor method instance in a .NET connectivity assembly and in a Web service.

Example for a .NET Connectivity Assembly

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

Example for an ASP.NET Web Service

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

Example for a WCF Service

The following shows the operation definition in the service contract interface.

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

The following example shows the implementation of the method instance.

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

See Also

Concepts

Implementing a StreamAccessor