다음을 통해 공유


Code Snippet: Implementing an AssociationNavigator

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

Example for a .NET Connectivity Assembly

public Order[] GetOrdersForCustomer(string custid)
{
    if (custid == "")
    {
        return orders.ToArray();
    }
    else
    {
        List<Order> ordersForCustomer = new List<Order>();

        foreach (Order order in orders)
        {
            if (order.CustomerID.Contains(custid))
            {
                ordersForCustomer.Add(order);
            }
        }

        return ordersForCustomer.ToArray();
    }
}

Example for an ASP.NET Web Service

[WebMethod]
public Order[] GetOrdersForCustomer(string custid)
{
    if (custid == "")
    {
        return orders.ToArray();
    }
    else
    {
        List<Order> ordersForCustomer = new List<Order>();

        foreach (Order order in orders)
        {
            if (order.CustomerID.Contains(custid))
            {
                ordersForCustomer.Add(order);
            }
        }

        return ordersForCustomer.ToArray();
    }
}

Example for a WCF Service

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

[OperationContract]
Order[] GetOrdersForCustomer(string custid);

The following example shows the implementation of the method instance.

public Order[] GetOrdersForCustomer(string custid)
{
    if (custid == "")
    {
        return orders.ToArray();
    }
    else
    {
        List<Order> ordersForCustomer = new List<Order>();

        foreach (Order order in orders)
        {
            if (order.CustomerID.Contains(custid))
            {
                ordersForCustomer.Add(order);
            }
        }

        return ordersForCustomer.ToArray();
    }
}

See Also

Concepts

Implementing an AssociationNavigator