1

I'm new to .NET and WCF framework. Currently, I'm building a simple windows application to consume WCF service. The windows client need to pass username parameter to WCF Service to save to database. How can I do that without passing parameter in every service requests ?

One thing to note is this service will call a method in another project to save to database , so actually I want to access the username parameter at this project layer.

Form1.cs

public async void Save()
{
     using(var client = new MyChannelFactory<WCFService>("WCFService"))
    {
         await Task.Run(() => client.Proxy.SaveData());
    }
}

WCFService.cs

public void SaveData()
{
    var _dataBL = new DataBL();
    _dataBL.SaveData();
}

DataBL.cs

public void SaveData();
{
    //need to get username from client
    string user = GetUserName();
    //save to database
} 

Something to note:

  • WCFService.cs and DataBL.cs are in different projects.

  • I'm not adding Service Reference to client project, instead I'm using a ChannelFactory to create service proxy.

  • I'm using wsHttpBinding

  • I'm not using Windows Authentication

This should be a common request but after read many articles from internet, I still couldn't make it work. Thanks for your help.

davidcoder
  • 898
  • 4
  • 11
  • 25

0 Answers0