In this paper, we propose a novel matching framework for Web service composition. The framework combines the concepts of Web service, context, and ontology. We adopt a broad definition of context for Web services, encompassing all information needed for enabling interactions between clients and providers. Context-based matching for Web services requires dealing with three major research thrusts: context categorization, modeling, and matching. We first propose an ontology-based categorization of contextual information in Web service environments. We then define a two-level mechanism for modeling Web service contexts. In the first level, service providers create context specifications using category-specific Web service languages and standards. In the second level, context specifications are enveloped by policies (called context policies) using WS-Policy standard. Finally, we present a peer-to-peer architecture for matching context policies. The architecture relies on a context matching engine, context policy assistants, and context community services. Community services implement rule-based techniques for comparing context policies.