What is the best way to confirm that these consumed services are actually up and running before I actually try to invoke its operation contracts? I want to do this so that I can gracefully display some message to the customer to give him/her a more pleasant user experience. Thanks.
在我实际尝试调用其操作合同之前,确认这些消耗的服务是否实际启动并运行的最佳方法是什么?我想这样做,这样我就可以优雅地向客户展示一些信息,让他/她获得更愉快的用户体验。谢谢。
2 个解决方案
#1
I created an IsAvailable
method that checked all of my underlying dependencies for my service. My client would call this method before doing anything else with my service. If it returned true, my service was available for use.
我创建了一个IsAvailable方法,该方法检查了我的服务的所有底层依赖项。在对我的服务做任何其他事情之前,我的客户会调用此方法。如果它返回true,我的服务可供使用。
We also put intermediaten checks to rollback any changes if one of the underlying dependencies was not able at the time of the transaction.
如果在事务处理时无法使用其中一个底层依赖项,我们还会使用intermediaten检查来回滚所有更改。
Example:
Here is a simple example of how my IsAvailable is used by the client:
以下是客户端如何使用我的IsAvailable的简单示例:
IsAvailable code
[WebMethod]
public bool IsAvailable()
{
bool EverythingUpAndRunning = true;
try
{
string TestConnectionString = WebConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(TestConnectionString);
sqlConnection.Open();
sqlConnection.Close();
sqlConnection.Dispose();
}
catch(Exception ex)
{
EverythingUpAndRunning = false;
}
return EverythingUpAndRunning;
}
The client code:
客户端代码:
MyWebService proxy = new MyWebService();
if(proxy.IsAvailable)
{
//if true, you can use the other available methods in the service
}
#2
I wouldn't consider myself a part of the SO Community but I have been in this situation before and it was simple exception handling around the service calls. If you're in control of the services, than you can put up a status method that returns it's current state. If the network is down and you can't even hit the service than you'll have to handle that with some exception handling but you could get a status back if the parent service is unable to use it's child services.
我不认为自己是SO社区的一部分,但我之前一直处于这种情况,这是围绕服务调用的简单异常处理。如果您控制服务,那么您可以建立一个返回其当前状态的状态方法。如果网络中断并且您甚至无法使用某些异常处理来处理该服务,但如果父服务无法使用它的子服务,您可以获得状态。
If you're following SO though, my own opinion here, you shouldn't be concerned with the consumed service consuming other services.
如果您正在关注SO,我自己的观点,您不应该关注消耗其他服务的服务。
#1
I created an IsAvailable
method that checked all of my underlying dependencies for my service. My client would call this method before doing anything else with my service. If it returned true, my service was available for use.
我创建了一个IsAvailable方法,该方法检查了我的服务的所有底层依赖项。在对我的服务做任何其他事情之前,我的客户会调用此方法。如果它返回true,我的服务可供使用。
We also put intermediaten checks to rollback any changes if one of the underlying dependencies was not able at the time of the transaction.
如果在事务处理时无法使用其中一个底层依赖项,我们还会使用intermediaten检查来回滚所有更改。
Example:
Here is a simple example of how my IsAvailable is used by the client:
以下是客户端如何使用我的IsAvailable的简单示例:
IsAvailable code
[WebMethod]
public bool IsAvailable()
{
bool EverythingUpAndRunning = true;
try
{
string TestConnectionString = WebConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(TestConnectionString);
sqlConnection.Open();
sqlConnection.Close();
sqlConnection.Dispose();
}
catch(Exception ex)
{
EverythingUpAndRunning = false;
}
return EverythingUpAndRunning;
}
The client code:
客户端代码:
MyWebService proxy = new MyWebService();
if(proxy.IsAvailable)
{
//if true, you can use the other available methods in the service
}
#2
I wouldn't consider myself a part of the SO Community but I have been in this situation before and it was simple exception handling around the service calls. If you're in control of the services, than you can put up a status method that returns it's current state. If the network is down and you can't even hit the service than you'll have to handle that with some exception handling but you could get a status back if the parent service is unable to use it's child services.
我不认为自己是SO社区的一部分,但我之前一直处于这种情况,这是围绕服务调用的简单异常处理。如果您控制服务,那么您可以建立一个返回其当前状态的状态方法。如果网络中断并且您甚至无法使用某些异常处理来处理该服务,但如果父服务无法使用它的子服务,您可以获得状态。
If you're following SO though, my own opinion here, you shouldn't be concerned with the consumed service consuming other services.
如果您正在关注SO,我自己的观点,您不应该关注消耗其他服务的服务。