将用户名从客户端传递到每个WCF服务调用

时间:2015-10-30 09:35:16

标签: c# .net wcf

我是.NET和WCF框架的新手。目前,我正在构建一个简单的Windows应用程序来使用WCF服务。 Windows客户端需要将username参数传递给WCF服务以保存到数据库。如果不在每个服务请求中传递参数,我怎么能这样做?

有一点需要注意的是,这个服务会在另一个项目中调用一个方法来保存到数据库,所以实际上我想在这个项目层访问username参数。

Form1.cs的

output$plot <- renderUI({
    ### here calculate the results all at once and save it to a variable
    result <- calculations

    for(i in 1:dim(result)[1]){
        Sys.sleep(0.5) # time to wait to perform each plot
        ### here you put the code to only get some results of
        ### the calculation you've perfomed earlier
        ggplot(results[i,...], ...)
    }
})

WCFService.cs

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

DataBL.cs

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

需要注意的事项:

  • WCFService.cs和DataBL.cs在不同的项目中。

  • 我没有在客户项目中添加服务参考,而是使用ChannelFactory创建服务代理。

  • 我正在使用wsHttpBinding

  • 我没有使用Windows身份验证

这应该是一个常见的请求,但在阅读了很多来自互联网的文章之后,我仍然无法使其发挥作用。 谢谢你的帮助。

0 个答案:

没有答案