如何设计多个WCF调用?
我有 2 个用 C# 实现的 WCF 服务,用于测试第 3 方应用程序的客户端-服务器交互。假设我有一个用于 WCF 测试服务的服务器端测试器接口(我跳过了属性并简化了接口)
interface IServerTester
{
bool Start();
}
和一个客户端测试器接口:
interface IClientTester
{
bool Start();
}
这些方法的目的仅仅是启动服务器并启动 3- 的客户端rd方应用程序。我正在使用 NUnit 来测试它。在上层,它看起来像一个 C# 事务脚本,我首先启动服务器,然后启动客户端,最后验证它们是否正在通信。
后来,我想轻松添加更多客户端(启动多个客户端),因此我需要在事务脚本中添加更多对 IClientTester
的 WCF 调用。
我可以做这样的事情,每个客户端都有自己的端点,
//Start server
//start client 1
//start client 2
//...
//start client N
我需要在许多其他测试中重用代码。但这似乎是一个相当长的解决方案。有没有更好的想法,或者我可以采用的模式?非常感谢!
I have 2 WCF services implemented in C# that test a client-server interaction of a 3-rd party application. Let's say I have a server-side tester interface for WCF test service (I skipped the attributes ans simplified the interfaces)
interface IServerTester
{
bool Start();
}
And a client side one:
interface IClientTester
{
bool Start();
}
The purpose of those methods is merely to start the server and to start the client of the 3-rd party application. I am using NUnit to test it. On the upper level it looks like a C# transaction script, where I first start a server, then a client and lastly verify that they are communicating.
Later, I want to easily add more clients (start more than one), thus I need to add more WCF calls to IClientTester
in my transaction script.
I can do something like this, with each client has its own endpoint
//Start server
//start client 1
//start client 2
//...
//start client N
I will need to reuse the code in many other tests.But it seems to be a rather long solution. Is there any better idea, or perhaps a pattern that I can adopt? Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否完全理解了你的问题,但对我来说这听起来像是对 Pub/Sub 的需求。听起来好像当服务器启动时,您希望 1:M 客户端收到通知并启动,对吗?如果是这样,那么服务器可以发布“客户端”都订阅的消息或事件。您无需修改任何内容即可添加新客户端,只需在新客户端实现中订阅消息或事件即可。
I'm not sure I completely followed your question, but it sounds to me like a need for Pub/Sub. It sounds like when the server starts, you want 1:M clients to be notified and also start, correct? If so, then the server could publish a message or event that the "clients" all subscribe to. You would not need to modify anything to add new clients, simply subscribe to the message or event in the new client implementation.