如何测试连接在C#一个未知的Web服务? [英] How do I test connectivity to an unknown web service in C#?

查看:98
本文介绍了如何测试连接在C#一个未知的Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忙着写监视RAS连接的状态的类。我需要测试,以确保连接不仅连接,而且它可以用我的网络服务进行通信。由于该课程将在未来的许多项目中使用,我想一个方法来测试不知道任何关于它连接到Web服务。

I'm busy writing a class that monitors the status of RAS connections. I need to test to make sure that the connection is not only connected, but also that it can communicate with my web service. Since this class will be used in many future projects, I'd like a way to test the connection to the webservice without knowing anything about it.

我想传球的URL类,以便它至少知道在哪里可以找到它。 ping服务器是不是有足够的考验。这是可能的服务器是可用的,但服务是脱机。

I was thinking of passing the URL to the class so that it at least knows where to find it. Pinging the server is not a sufficient test. It is possible for the server to be available, but the service to be offline.

我怎样才能有效地测试,我是能够得到从Web服务的响应?

How can I effectively test that I'm able to get a response from the web service?

推荐答案

您是正确的,ping服务器是不够的。该服务器可以,但网络服务不可用,由于多种原因。

You are right that pinging the server isn't sufficient. The server can be up, but the web service unavailable due to a number of reasons.

要监督我们的Web服务的连接,我创建了一个有一个方法CheckService一个IMonitoredService接口()。每个Web服务的包装类实现此方法来调用Web服务和报告无害的方法,如果服务或没有。这使得与出负责监控了解服务细节的代码监控任何数量的服务。

To monitor our web service connections, I created a IMonitoredService interface that has a method CheckService(). The wrapper class for each web service implements this method to call an innocuous method on the web service and reports if the service is up or not. This allows any number of services to be monitored with out the code responsible for the monitoring knowing the details of the service.

如果你知道一点什么,Web服务将直接访问网址回报,你可以尝试只使用URL。例如,微软的ASMX文件返回网络服务的概要。其他实现行为可能不同,但。

If you know a bit about what the web service will return from accessing the URL directly, you could try just using the URL. For example, Microsoft's asmx file returns a summary of the web service. Other implementations may behave differently though.

这篇关于如何测试连接在C#一个未知的Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆