wcf - 如何在 Xamarin.Forms 项目中使用 .netstandard 中的 WCF 服务?

标签 wcf xamarin xamarin.forms .net-standard

我用 .netstandard 2.0 作为 PCL 项目创建了一个 Xamarin.Forms 项目。我正在尝试在该项目中使用 WCF 服务。我已经为 WCF 服务添加了连接服务。当我尝试调用服务中提供的任何方法时,它会给出如下错误:

System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Error in deserializing body of request message for operation 'GetData'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetData' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'GetDataAsync' and namespace 'http://tempuri.org/'



我也尝试将 .netstandard 版本更改为旧版本,但它给出了相同的错误。

最佳答案

目前,Xamarin 应用程序与 WCF Web Service Reference 的基于任务的异步 WCF 代理方法不兼容。连接的服务提供程序为 .NET Standard 项目生成 (bugzilla.xamarin.com Bug 51959)。

生成旧的、兼容样式的 WCF 代理方法的一种方法是运行 SvcUtil.exe /async/tcv:Version35Developer Command Prompt 中切换.这将生成同步代理方法、开始/结束样式异步编程模型 (APM) 回调代理方法和基于事件的代理方法,所有这些都与 Xamarin 应用程序兼容。

(注意:如果您忽略 /async 开关,SvcUtil.exe 将生成更新的、不兼容的基于任务的代理方法。)

关于wcf - 如何在 Xamarin.Forms 项目中使用 .netstandard 中的 WCF 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47989563/

相关文章:

xamarin - 如何从 TFS 连接 Visual Studio 应用程序中心(本地)

无论我做什么,WCF 服务都只处理 10 个并发调用

c# - 什么可能导致 WCF 中出现 "Cannot access a disposed object"错误?

xaml - 第一项比 collectionview xamarin 表单中的其他项宽

xamarin - 如何在 Xamarin iOS 项目中禁用位码?

c# - xaml.cs 中的 Xamarin 局部变量并通过 XAML 文件打印

java - WCF 方法中的“Out”变量可以在 Java 客户端中使用吗?

c# - 任务异步困惑

ios - 当用户扫描其中包含 URL 的二维码时如何打开 iOS 应用程序

ios - 对象引用未设置到对象的实例 - Select 语句 Sqlite Xamarin iOS