[英]Multiple Async Methods, best to use WhenAll with different return types
[英]Why there are Response return types in WCF async methods?
我在WCF中不是那么完美,仍然是一個學習者。 我學習WCF服務的地方告訴我WCF服務的Async方法還返回與原始方法相同的數據類型。 在我下載的項目上運行正常,但是使用相同的配置,我創建了一個新項目,並且該項目未返回原始方法的數據類型。 相反,響應類型如下:
如您所見,其顯示為isEmailExistsResponse
類型。 如何使其返回布爾類型?
我的配置
客戶端:
<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客戶端設置:
您需要await
Async方法:
var isEmailExists = await client.isEmailsExistsAsync(email);
if (isEmailExists == false) {
...
}
無論在哪里看到Task<SomeOtherType>
的返回類型,都必須使用新的await
關鍵字來處理它的屬性。
http://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.