我有一个WCF服务——客户。 我们一直依靠公开招标,使用客户工厂方法,确保在我们发出任何呼吁之前提供服务。 类似:
MyClient GetClient()
{
MyClient client = new MyClient();
try
{
client.Open();
return client;
}
catch(Exception)
{
//perform an (important) error-handling here
}
}
这样,打电话者守则就能够做到:
client = factory.GetClient();
client.CallMethodInTheService();
他们不必担心错误处理。
当我们为Windows和客户CredentialType设定安全模式时,客户(Open()在无法提供服务时将放弃一个例外,因此,错误处理法将得到执行。 然而,我们现在是在我们不能使用视窗成像安全的环境中部署的,因此,我们把安全模式设定为零。 然而,这会造成客户。 开放(开放)不再成为无法提供服务的例外情况,而且我们有一些问题,因为我们在工厂的集水区依靠这一守则。
What is the reason that Open() throws an exception when we use message security but not when we disable the security? How can we perform similar availability checking if security is set to none? I don t think it s a good solution to put a try catch with error handling on each individual call. Is there another way for the factory method to check the availability of the service before returning the client object?