Possible Duplicate:
How to add custom soap headers in wcf?
Here's the scenario:
I have a WCF service which we'll call "BusinessService."
I also have a web app which has a client of this service to send requests.
I want to be able to log who is sending an update to my service; because of this, my BusinessService has a private string member called _userID as well as a method to set this _userID, this class looks like this:
public class BusinessService : IBusinessService
{
private string _userID;
public void SetUserID(string userID)
{
_userID = userID;
}
public void UpdateCustomer(Customer customer)
{
// update customer here.
}
}
Because of the way the above class is written (since it isn't easy to have a custom custructor for WCF services in which I can just pass the userID,) then my web app is written like so:
public class WebApp
{
private string _userID; // on page load this gets populated with user's id
// other methods and properties
public void btnUpdateCustomer_Click(object sender, EventArgs e)
{
Customer cust = new Customer();
// fill cust with all the data.
BusinessServiceClient svc = InstantiateWCFService();
svc.UpdateCustomer(cust);
svc.Close();
}
private BusinessServiceClient InstantiateWCFService()
{
BusinessServiceClient client = new BusinessServiceClient("EndPointName");
client.SetUserID(_userID);
return client;
}
}
When looking at the data stored, nothing is saved for the user id.
Is there some form of design pattern, or feature that allows me to log who is making some change without having my service require the userID in every method call?