如何获取使用C#的Web服务的状态?无论它是否成功完成,失败或等待如此。如何获取Web服务的状态
2
A
回答
0
首先,我发现这个问题Web Service For Database/Website Status
你应该试试这个代码;
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController("myService");
return sc.Status
而你应该检查这段代码;
public static string PingHost(string args)
{
HttpWebResponse res = null;
try
{
// Create a request to the passed URI.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(args);
req.Credentials = CredentialCache.DefaultNetworkCredentials;
// Get the response object.
res = (HttpWebResponse)req.GetResponse();
return "Service Up";
}
catch (Exception e)
{
MessageBox.Show("Source : " + e.Source, "Exception Source", MessageBoxButtons.OK);
MessageBox.Show("Message : " + e.Message, "Exception Message", MessageBoxButtons.OK);
return "Host Unavailable";
}
}
而且你也应该看看;
0
如果要调用在同步模式下你的web服务,没有与获取状态没有问题。
如果您在异步模式下调用webservice,则应该设置回调函数并跟踪返回给该回调函数的结果中的web服务状态。
1
private void button1_Click(object sender, EventArgs e)
{
var url = "servicsURL";
try
{
var myRequest = (HttpWebRequest)WebRequest.Create(url);
NetworkCredential networkCredential = new NetworkCredential("UserName", "password","domain");
// Associate the 'NetworkCredential' object with the 'WebRequest' object.
myRequest.Credentials = networkCredential;
var response = (HttpWebResponse)myRequest.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
// it's at least in some way responsive
// but may be internally broken
// as you could find out if you called one of the methods for real
MessageBox.Show(string.Format("{0} Available", url));
}
else
{
// well, at least it returned...
MessageBox.Show(string.Format("{0} Returned, but with status: {1}", url, response.StatusDescription));
}
}
catch (Exception ex)
{
// not available at all, for some reason
MessageBox.Show(string.Format("{0} unavailable: {1}", url, ex.Message));
}
}
相关问题
- 1. Web服务状态
- 2. Web服务状态的HashMap
- 3. 有状态的Web服务
- 4. 有状态与无状态Web服务
- 5. 有状态web服务
- 6. KSOAP2:获取Web服务响应的http状态码
- 7. 无法获取服务的状态powershell
- 8. 获取Windows服务的禁用状态
- 9. 获取C服务状态++的Linux
- 10. 使用SharePoint Web服务获取工作流状态
- 11. javascript从服务中获取状态
- 12. C++获取服务网络状态linux
- 13. 获取HTTP状态服务器
- 14. PHP - 获取Minecraft服务器状态?
- 15. Windows命令获取服务状态?
- 16. AFNetworking + JSON和获取服务器状态
- 17. C#WCF服务获取状态代码
- 18. Azure移动服务InsertAsync获取状态
- 19. 从android服务获取当前状态
- 20. 有状态Web服务与(状态Bean +无状态WS)
- 21. 如何获取Google应用服务的状态?
- 22. 如何从我的服务中获取状态?
- 23. 无论如何flex中获取服务器的状态吗?
- 24. 如何获取远程机器的MySQL服务状态?
- 25. 如何获取JBoss应用程序服务器的状态
- 26. 如何获取芹菜任务状态?
- 27. 有状态的WCF Web服务
- 28. C Web服务器 - 如何获取URI?
- 29. openshift - 如何获取Web服务端点
- 30. 如何从Web服务获取数据?
我试过你的解决方案,但它提供异常服务'myservice'没有在计算机'computername'上找到。 – smartDev 2011-04-12 07:16:33