Callers of a Custom X++ Service can specify CallContext as part of the operation signature on the generated service reference proxy. See However the operation signatures for AX System services, like the Query Service and Metadata Service, do not include a CallContext parameter. The call context needs to be passed in manually as an operation header using a few WCF tricks.

The linked sample code walks through the scenario of listing the companies for a given AX partition. This requires the caller to specify the PartitionKey value as part of the CallContext operation header.  Similar approach can be used for other CallContext scenarios including setting of Company context or specifying a LogOnAs value.

Access the code sample here:

After downloading the sample code run through the following steps:

1. Create a new Parition.
2. Open the AX client to show created partition.
3. Create company accounts.
4. Set value of PartitionKey in code as appropriate.
5. Run the application in debug mode.
Since the CallContext data contract is not available for these services, the following data contract can be used to code against.
/// <summary>
/// Call Context data contract to be used as header with system service calls.
/// </summary>
[DataContract(Name = CallContext.Name, Namespace = CallContext.Namespace)]
public class CallContext
    public const string Name = "CallContext";
    public const string Namespace = "";

    public string Company { get; set; }

    public string Language { get; set; }

    public string LogonAsUser { get; set; }

    public string MessageId { get; set; }

    public string PartitionKey { get; set; }

The code required for adding the call context to the operation header is as follows:
// Get client channel and the equivalent object cast to service interface 
var channel = queryClient.InnerChannel; 
var queryChannel = (QueryService.IQueryService)channel; 
// Create an operation context scope 
using (OperationContextScope operationContextScope = new OperationContextScope(channel)) 

    // Add Call Context header to current operation context 
    var header = MessageHeader.CreateHeader(CallContext.Name, CallContext.Namespace, callContext); 
    // Execute service operation 
    QueryService.Paging paging = null
    dataSet = queryChannel.ExecuteQuery(query, ref paging);