多形态环境下与Web服务通信的最佳方式
场景是,我们有一个 winforms 应用程序,它在主窗体上引用了一些通过 WCF 和 STS/WIF 保护的 Web 服务。
凭证管理是在此主表单上处理的,但我们有很多子表单和用户控件等需要访问这些 Web 服务。
目前,Web 服务已实例化,然后在需要时调用,但现在它们通过 WCF 进行保护,实际上我们只需要在主表单上对它们的引用,否则我们需要在表单之间传递凭据以重新启动。 -创建安全性-这避免了处理安全性一次的问题。
您认为将对父(主)窗体上的服务的引用传递给这些其他窗体和控件的最佳方法是什么?
提前致谢。
The scenario is that we have a winforms application that has on the main form references to some webservices that are secured via WCF and an STS/WIF.
The credential management is handled on this main form, but we have a lot of sub forms and user controls etc that need access to these webservices.
At the moment the webservices are instantiated and then called at the point of need, but now they are secured via WCF, really we only need the references to them on the main form, otherwise we'll need to pass the credentials between forms to re-create the security - which evades the point of handling the security once.
What would you consider to be the best way to pass a reference to the services on the parent (main) form to these other forms and controls?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在其他形式的构造函数中传递Web服务对象,如下所示
var childForm = new ChildForm(theServiceObject);
将其放入静态单吨中,每个表单都可以像这样从那里获取它
var theServiceObject = ServiceInstance.Get();
在主窗体完成凭据验证后,使用 IOC 容器并让其他窗体通过属性、方法或构造函数注入获取服务
Pass the web service object in constructor of the other forms like so
var childForm = new ChildForm(theServiceObject);
Put it in some static single ton and every form can get it from there like so
var theServiceObject = ServiceInstance.Get();
Use IOC container and have the other forms get the service via property, method or constructor injection after the main form has done the credential verification