C#在客户端管理多个WCF服务的调用 [英] C# Manage call for multiple WCF Service on client side

查看:233
本文介绍了C#在客户端管理多个WCF服务的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在多个IIS服务器上托管了一个WCF服务(在C#中)。我有一个访问这些服务的REST API(C#)。我希望如果server1上的WCF服务无法响应(或临时关闭),那么Rest API会调用server2获取相同的函数并获取数据。如果server2也失败,那么检查server3等等......



我不想为此使用GetMetaData。请帮我解决这个问题。



非常感谢。!

I have a WCF Service(in C#) hosted on multiple IIS servers. And I have a REST API(C#) accessing these service. I want that if WCF service on server1 failed to respond(or temporary down) then Rest API makes call to server2 for the same function and get data. if server2 also fails then check for server3 and so on...

I don't want to use GetMetaData for this. Please help me out of this problem.

Thanks very much.!

推荐答案

检查以下代码





静态IEnumerable< uri> GetServiceUris()

{

收益率返回新的Uri(SERVICE1);

收益率返回新的Uri(SERVICE2);

收益率返回新的Uri(SERVICE3);

收益率返回新的Uri(SERVICE4);

收益率返回新的Uri(SERVICE5);

}





public static int Main(params string [] args)

{

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();

foreach(Uri uri in GetServiceUris())

{

尝试

{

IService client = ChannelFactory< iservice> .CreateChannel(basicHttpBinding ,uri);



if(client.DoWork())

休息;

}

catch

{

}

}

返回0;

}
check the following code


static IEnumerable<uri> GetServiceUris()
{
yield return new Uri("SERVICE1");
yield return new Uri("SERVICE2");
yield return new Uri("SERVICE3");
yield return new Uri("SERVICE4");
yield return new Uri("SERVICE5");
}


public static int Main(params string[] args)
{
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
foreach (Uri uri in GetServiceUris())
{
try
{
IService client = ChannelFactory<iservice>.CreateChannel(basicHttpBinding, uri);

if (client.DoWork())
break;
}
catch
{
}
}
return 0;
}


这篇关于C#在客户端管理多个WCF服务的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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