简体   繁体   English

无法获得调用WCF服务的异步方法-异步新手

[英]Can't get async method that calls WCF service to work - async newbie

I need to test async calls to an external SOAP service. 我需要测试对外部SOAP服务的异步调用。 I have a Main program that builds requests to the web service (it will eventually become a Windows service, but keeping it simple for debug purposes). 我有一个Main程序,它生成对Web服务的请求(它最终将成为Windows服务,但出于调试目的而保持简单)。 The Main program calls the service multiple times from within a loop. 主程序从一个循环中多次调用该服务。 I need to build the SOAP request dynamically, so I have a class that does this and within that class I have an async method that looks like this: 我需要动态地构建SOAP请求,因此我有一个做到这一点的类,并且在该类中有一个异步方法,如下所示:

public async Task<WebServiceResponse> ExecuteWebService()
{
     var request = BuildRequest(); //non-async: builds dynamic SOAP request
     var retrieveDataClient = new ExternallyProvidedInterfaceClient();
     retrieveDataClient.Open();
     return await retrieveDataClient.RetrieveDataAsync(request);
}

My problem is this: When I debug the method above, it returns as soon as the external client constructor is called (second line). 我的问题是:当调试上述方法时,一旦调用外部客户端构造函数,它就会返回(第二行)。 The Open() method is never called and the actual SOAP call is never made. 永远不会调用Open()方法,也永远不会进行实际的SOAP调用。

I'm new to async programming...can someone show me where I went wrong and explain why the method returns BEFORE it reaches the return statement? 我是异步编程的新手...有人可以告诉我我哪里出错了,并解释为什么该方法在到达return语句之前返回?

My stupid. 我的笨蛋 I ran SvcUtil on a service that had already provided an InterfaceClient. 我在已经提供InterfaceClient的服务上运行SvcUtil。 This created a local copy of the client. 这创建了客户端的本地副本。 When I executed the constructor, it was getting confused between the two. 当我执行构造函数时,两者之间变得很困惑。 Deleted the local copy of the InterfaceClient class and all is well. 删除了InterfaceClient类的本地副本,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM