c# - 为什么 WCF 异步方法中有 Response 返回类型?

标签 c# asp.net .net wcf web-services

我在 WCF 方面不是很完美,而且还是一个学习者。我学习 WCF 服务的地方告诉我 WCF 服务异步方法也返回与原始方法相同的数据类型。它在我下载的项目上运行良好,但使用相同的配置我创建了一个新项目并且它没有返回原始方法的数据类型。而是像这样的响应类型:

enter image description here

如您所见,它显示了 isEmailExistsResponse 类型。 如何让它返回 bool 类型?

我的配置

客户端:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WCORE.IService1" name="BasicHttpBinding_IService1"/>
    </client>
  </system.serviceModel>

服务器端:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

我在客户端和服务上都使用 .NET 4.5。但是我的服务器安装的是4.0。因此,如果服务在最终部署时遇到问题,我可能会切换到 4.0。

WCF 客户端设置: enter image description here

最佳答案

您需要等待 Async 方法:

var isEmailExists = await client.isEmailsExistsAsync(email);
if (isEmailExists == false) {
...
}

关于c# - 为什么 WCF 异步方法中有 Response 返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144916/

相关文章:

c# - QueryString containing\coming through with\\

c# - jQuery如何在删除属性之前检查属性是否存在

.net - IBM MQ .NET 库不读取 app.config

.net - 在 Visual Studio 中构建具有大量控件的 GUI

C#异常处理,使用哪个catch子句?

c# - 在 C# 中将 reg 值写入本地计算机

c# - 在 Unity 中的类型之间共享生命周期管理器?

javascript - 有没有办法在 ASP.Net 页面中悬停在 html 元素上时更改它

c# - 使用PrincipalContext和PrincipalSearcher从单独的服务器访问Active Directory用户

.net - 制作 "hotkey"以在 WPF 中聚焦 TextBox