다음을 통해 공유


Code Snippet: Implementing an Associator

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 an Associator method instance in a .NET connectivity assembly and in a Web service.

Example for a .NET Connectivity Assembly

public void AssociateCustomerRegion(String customerid, String regionid)
{
    if (customerregions.Find(
        cr => cr.CustomerID == customerid 
            && cr.RegionID == regionid) == null)
        customerregions.Add(
            new CustomerRegion() 
            { CustomerID = customerid, RegionID = regionid });
    return;
}

Example for an ASP.NET Web Service

[WebMethod]
public void AssociateCustomerRegion(String customerid, String regionid)
{
    if (customerregions.Find(
        cr => cr.CustomerID == customerid 
            && cr.RegionID == regionid) == null)
        customerregions.Add(
            new CustomerRegion() 
            { CustomerID = customerid, RegionID = regionid });
    return;
}

Example for a WCF Service

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

[OperationContract]
void AssociateCustomerRegion(string customerid, string regionid);

The following example shows the implementation of the method instance.

public void AssociateCustomerRegion(String customerid, String regionid)
{
    if (customerregions.Find(
        cr => cr.CustomerID == customerid 
            && cr.RegionID == regionid) == null)
        customerregions.Add(
            new CustomerRegion() 
            { CustomerID = customerid, RegionID = regionid });
    return;
}

See Also

Concepts

Implementing an Associator