简体   繁体   English

C#-WCF客户端/服务器在服务应用程序上打开控制台

[英]C# - WCF Client/Server Open a Console on Service Application

the problem is bigger, but I try reducing it to a simpler style: 问题更大,但我尝试将其简化为更简单的样式:

Lets assume, that I am simply programming a Client/Server Model. 让我们假设,我只是在编写客户机/服务器模型。 I manage to connect to the Service and can use its function and am able to communicate. 我设法连接到该服务,并且可以使用其功能并且能够进行通信。 The connection is build up through a configuration file on server site and the client just connects to it in his Main function by creating a Channelfactory to a WsHTTPEndpoint. 连接是通过服务器站点上的配置文件建立的,客户端只需在其Main函数中通过创建WsHTTPEndpoint的Channelfactory来连接该连接。 So everything is fine. 所以一切都很好。 I can communicate via a console with the server and see actually what is happening. 我可以通过控制台与服务器通信,并查看实际发生的情况。

But let's imagine now, I am programming a server which provides a service, but also is a client at a different service application. 但是,现在让我们想象一下,我正在对提供服务的服务器进行编程,但它也是另一个服务应用程序的客户端。 I want to test whether the connection works and whether I can send some requests, but there is no console I can write in. Thus, it is hard for me to see, whether something works or something does not. 我想测试连接是否有效,是否可以发送一些请求,但是没有可以写入的控制台。因此,我很难看出是可行还是不可行。

How can I start the server and in the same time use a console on it like in a normal client application? 如何启动服务器,同时像在普通客户端应用程序中一样,在服务器上使用控制台?

If you require this for development purposes, I can recommend unit testing. 如果出于开发目的需要此功能,我建议您进行单元测试。 Before I used unit testing, I would develop somewhat like you describe: create a console server and client and interact with the console client to see whether the send and received data makes sense. 在使用单元测试之前,我会像您描述的那样进行开发:创建一个控制台服务器和客户端,并与控制台客户端进行交互,以查看发送和接收的数据是否有意义。

What I do now with unit testing, is that I create small tests that do roughly the same as what I would do manually through the client console. 我现在使用单元测试所做的是,我创建了一些小型测试,这些测试与通过客户端控制台手动进行的测试大致相同。 The unit testing approach has the following advantages: 单元测试方法具有以下优点:

  • The tests are small and clear, so I know what I'm testing; 测试小而清晰,所以我知道我在测试什么;

  • The tests are repeatable so I know that when all tests pass, the small piece that I tested before still works; 这些测试是可重复的,因此我知道,当所有测试通过时,我之前测试过的一小块仍然有效;

  • The tests are easy to run, just as easy as the console client; 测试很容易运行,就像控制台客户端一样容易。

  • When I have created enough tests, I can use this component in an application where I cannot interact with the console. 创建足够的测试后,可以在无法与控制台交互的应用程序中使用此组件。 I don't have to worry anymore whether everything works because the unit tests tested this for me. 我不必担心一切是否正常,因为单元测试已经为我测试了这一点。

This approach has made my live much easier. 这种方法使我的生活更加轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM