我在 WCF 方面不是很完美,而且还是一个学习者。我学习 WCF 服务的地方告诉我 WCF 服务异步方法也返回与原始方法相同的数据类型。它在我下载的项目上运行良好,但使用相同的配置我创建了一个新项目并且它没有返回原始方法的数据类型。而是像这样的响应类型:
如您所见,它显示了 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 客户端设置:
最佳答案
您需要等待
Async 方法:
var isEmailExists = await client.isEmailsExistsAsync(email);
if (isEmailExists == false) {
...
}
关于c# - 为什么 WCF 异步方法中有 Response 返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144916/