简体   繁体   English

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

[英]Why there are Response return types in WCF async methods?

I am not so perfect in WCF and still a learner. 我在WCF中不是那么完美,仍然是一个学习者。 The place where I learnt WCF services taught me that WCF service Async method also return the same datatype as of the original method. 我学习WCF服务的地方告诉我WCF服务的Async方法还返回与原始方法相同的数据类型。 It was working fine on the project I downloaded but with same configuration I created a new project and its not returning the original method's data type. 在我下载的项目上运行正常,但是使用相同的配置,我创建了一个新项目,并且该项目未返回原始方法的数据类型。 Instead a response type like: 相反,响应类型如下:

在此处输入图片说明

As you can see its showing isEmailExistsResponse type. 如您所见,其显示为isEmailExistsResponse类型。 How can I make it to return bool type? 如何使其返回布尔类型?

My Configuration 我的配置

Client Side: 客户端:

<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>

Server side: 服务器端:

<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>

I am using .NET 4.5 on both client and service. 我在客户端和服务上都使用.NET 4.5。 But my server is installed with 4.0. 但是我的服务器安装了4.0。 So I may switch to 4.0 if service encountered some problem on final deployment. 因此,如果服务在最终部署时遇到问题,我可能会切换到4.0。

WCF Client Settings: WCF客户端设置: 在此处输入图片说明

You need to await the Async method: 您需要await Async方法:

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

Wherever you see a return type of Task<SomeOtherType> you will have to use the new await keyword to handle it property. 无论在哪里看到Task<SomeOtherType>的返回类型,都必须使用新的await关键字来处理它的属性。

http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx

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

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