Question: I have a WCF data service, which works fine. But now I want it to be able to use a different database based on a parameter that is sent by the consumer of my data service. 

Concrete example: a client from US that uses the data service passes 'US' as a parameter, and so the data service uses the US database. Another client from Belgium that uses the data service passes 'BE' as a parameter, so the data service uses the BE database. Of course all databases have same schemas.

Currently my client uses the data service like:

```
var qclient = new QueryServiceReference.Complaint_Entities(new Uri("http://localhost:60642/QueryService.svc"));

```

But how would it be possible to add a parameter to this? And how can I check this parameter in the data service?

So my question is: how to pass a parameter to a WCF data service?

EDIT: I found a way, but I don't know if it's the best method to do it. Before doing the request, I add the parameter to the request header:

```
 var qclient = new QueryServiceReference.Complaint_Entities(new Uri("http://localhost:60642/QueryService.svc"));
 qclient.SendingRequest += new EventHandler<System.Data.Services.Client.SendingRequestEventArgs>(qclient_SendingRequest);
 var cat = qclient.Categories.ToList();

static void qclient_SendingRequest(object sender, System.Data.Services.Client.SendingRequestEventArgs e)
{
   e.RequestHeaders.Add("Culture", "nl-BE");            
}

```

In the data service, I can then use it to set the connection string:

```
protected override Complaint_Entities CreateDataSource()
{
    var culture = HttpContext.Current.Request.Headers["Culture"];   
    // set connectionString based on culture
    return new Complaint_Entities(connectionString);    
}

```

Thanks,
L

Answer: 
Finally found how to do it, here's how.

The client has to send the parameter before doing the query, which he can do by adding it to the request header as follows:

```
  var client = new QueryServiceReference.Complaint_Entities(new Uri("http://localhost:60642/QueryService.svc"));
  client.SendingRequest += (o, eventArgs) => eventArgs.RequestHeaders.Add("Culture", "nl-BE");
  var result = client.Categories.ToList();

```

In the data service, you then can set the connection string to be used depending on this parameter by overriding the CreateDataSource method:

```
public class QueryService : DataService<Complaint_Entities>
{
    protected override Complaint_Entities CreateDataSource()
    {
        var culture = HttpContext.Current.Request.Headers["Culture"];
        string connectionStringName = string.Format("name=Complaint_Entities_{0}", culture);
        return new Complaint_Entities(connectionStringName);
    }
}

```
That is fairly easy, all you have to do is to create a proper data context depending on the parameter value:

```
switch ( parameterValue ) {
   case "US" : datacontext = new ....( "US connectionstring" );
   case "EN" : datacontext = new ....( "BE connectionstring" );
}

```

However, there's a caveat and it's **authentication**. 

You have to design a mechanism to authenticate your requests so that it is impossible for US users to craft requests to BE database and vice versa.