Web 服务调用的同步性
默认情况下,Web 服务调用是同步还是异步?同步性是如何由服务或客户端确定的?
我的代码类似于以下内容:
try
{
string result = MakeWebServiceCall_1(); // this is a third party webservice
MakeWebServiceCall_2(result); // another webservice which must happen *after* the first one is complete
}
catch()
{
SetStatus(Status.Error); // this calls my own stored procedure
throw;
}
SetStatus(Status.Sucess);
在上面,SetStatus
正在写入第三方 Web 服务从中读取的相同表。如果我在两个 Web 服务调用完成之前更改状态,就会造成大混乱,而且我会被解雇。我如何知道/确保 Web 服务调用是同步的?
Are web service calls synchronous or asynchronous by default? How is synchronicity determined, by the service or by the client?
I have code similar to the following:
try
{
string result = MakeWebServiceCall_1(); // this is a third party webservice
MakeWebServiceCall_2(result); // another webservice which must happen *after* the first one is complete
}
catch()
{
SetStatus(Status.Error); // this calls my own stored procedure
throw;
}
SetStatus(Status.Sucess);
In the above, SetStatus
is writing to the same tables that the third party web services read from. If I change the status before both web service calls have completed, it's going to make a big mess and I'm going to get fired. How do I know/ensure that the webservice calls are synchronous?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 MSDN,当您添加对 Web 服务的引用时,它将在代理类中实现同步和异步调用 Web 服务的方法。您只需确保拨打正确的电话即可。
使用“添加 Web 引用”对话框找到供应用程序访问的 XML Web 服务后,单击“添加引用”按钮将指示 Visual Studio 将服务描述下载到本地计算机,然后生成一个代理类所选的 XML Web 服务。代理类将包含用于同步和异步调用每个公开的 XML Web 服务方法的方法。 来源
According to MSDN when you add a reference to a Web Service it will implement methods to call the Web Service both synchronously and asynchronously in the proxy class. You just need to make sure you call the right one.
After you have located an XML Web service for your application to access by using the Add Web Reference dialog box, clicking the Add Reference button will instruct Visual Studio to download the service description to the local machine and then generate a proxy class for the chosen XML Web service. The proxy class will contain methods for calling each exposed XML Web service method both synchronously and asynchronously. Source