ASP.NET 上的 SOAP Web 服务 - 多个连接 - 静态值 - XMLRPC API
拥有一个封装对第 3 方 API 的调用的 SOAP Web 服务...因此我们的应用程序可以简单地调用我的服务,然后我的服务处理对 API 的所有各种调用。效果很好。
然而,我们遇到了一个问题,即我们连接的 API 在任何给定时间对于一组给定的凭据最多允许 10 个连接。
连接最多需要几秒钟的时间来处理,但是当我们上线时,理论上我们可以让用户最大化这个时间。因此,我们为 API 创建了多个帐户 (5),为 5 个用户提供了 50 个连接。
ASP.NET 如何处理与 Web 服务的连接?我知道它是异步工作的,但它是否会生成我的类的多个实例或重用同一个类。变量会在实例之间持续存在吗(即静态变量会起作用)吗?
我需要做的是,如果对 API 的调用在 Client1 上失败,则滚动到 Client2(或 Clients[0]、Clients[1])等...遗憾的是,我无法检测给定的 Client 是否失去连接在任何特定时刻。我可以通过测试调用来轮询它,但这需要时间,并且不能保证客户端在我进行调用时有可用的连接。
我调用的 API 是通过 XMLRPC 代理类 (CookComputing) 进行的。创建客户端时或进行调用时是否会建立“连接”并传递凭据?
public static IVoicestar GetClient(string userID, string password)
{
IVoicestar client = XmlRpcProxyGen.Create<IVoicestar>();
client.Credentials = new NetworkCredential(userID, password);
return client;
}
由此看来,凭证只是“一直运行”,直到我通过 Client.MethodCall() 进行调用,然后建立连接。
Have a SOAP Web Service that encapsulates calls to a 3rd party API... so our application can simply call my service and then my service handles all the various calls to the API. Works just fine.
However, we've hit a problem where the API we're connecting to allows a max of 10 connections at any given time for a given set of credentials.
Connections at most take a couple of seconds to process, but when we go live, we could in theory have users that max out this. So we've created multiple accounts (5) to the API giving us 50 connections across the 5 users.
How does ASP.NET handle connections to the Web service? I know it works asynchronously, but does it spawn multiple instances of my class or reuse the same class. Will variables persist across instances (i.e Will static variables work)?
What I need to do is if a call to the API fails on Client1, rollover to Client2 (or Clients[0], Clients[1]) etc... Sadly I have no way to detect if a given Client is out of connections at any given moment. I could poll it with a test call, but that would take time and be no guarantee the the client has a connection available when I make the call.
The API I'm calling is via XMLRPC Proxy class (CookComputing). Is the "connection" made when the Client is created or when the call is made, passing along the credentials?
public static IVoicestar GetClient(string userID, string password)
{
IVoicestar client = XmlRpcProxyGen.Create<IVoicestar>();
client.Credentials = new NetworkCredential(userID, password);
return client;
}
Seems from this that the credentials simply "ride along" until I make a call via Client.MethodCall() and then the connection is made.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 ASP.NET Web 服务 (asmx),那么它将为每个请求生成一个 Web 服务类的新实例。如果是基于 WCF 的 Web 服务,您可以使用属性/配置来控制实例化/并发(请参阅此 文章) - 您可以使用三种实例化模式 - 每次调用、每次会话和单例。
无论您使用什么,您始终可以实现自己的池机制来池化您的 API 连接。您已经有一个工厂方法来获取 API 客户端 - 只需在方法中调用池层即可。
If you are using ASP.NET Web Services (asmx) then it would spawn a new instance of your web service class for each request. In case WCF based web services, you can control the instancing /concurrency using attributes/configuartion (see this article) - you have three instancing modes possible - per call, per session and singleton.
Irrespective of what you are using, you can always implement your own pooling mechanism to pool your API connection. You already have a factory method to get the API client - just put call to pooling layer within method.
通常,Windows XP 和 Windows 7 的并发 TCP/IP 连接数限制为 10 个。也许就是这样。确保在 Windows 服务器版本中工作。
Normally Windows XP and Windows 7 have a limit of 10 concurrent TCP/IP connections. Maybe that's it. Be sure to work in a windows server version.