表单在仅WCF生成的异步方法上添加连接的服务

表单在仅WCF生成的异步方法上添加连接的服务,wcf,xamarin.forms,async-await,.net-standard-2.0,Wcf,Xamarin.forms,Async Await,.net Standard 2.0,我刚刚开始用.Net标准2.0(PCL)项目编写Xamarin.Forms。我正在尝试使用我的WCF web服务,但从未成功完成 我创建了一个简单的WCF,如下所示 [ServiceContract] public interface IWcfConnection { [OperationContract] string GetHelloWorld(); } 实施过程如下所示 public class WcfConnection : IWcfConnection

我刚刚开始用.Net标准2.0(PCL)项目编写Xamarin.Forms。我正在尝试使用我的WCF web服务,但从未成功完成

我创建了一个简单的WCF,如下所示

[ServiceContract]
public interface IWcfConnection
{        
    [OperationContract]
    string GetHelloWorld();
}
实施过程如下所示

public class WcfConnection : IWcfConnection
{
    public string GetHelloWorld()
    {
        return "Hello World";
    }
}
这是一个非常简单的WCF,当我转到我的Xamarin.Forms并右键单击“连接的服务”时,没有“添加Web服务”,只有“添加连接的服务”,所以我选择了它,如下所示

然后选择“Microsoft WCF Web服务提供商”

选择如下选项(我取消勾选所有内容,因为如果我添加多个服务,它将崩溃)

当我查看创建的reference.cs时,只创建了异步方法

public System.Threading.Tasks.Task<string> GetHelloWorldAsync()
{
    return base.Channel.GetHelloWorldAsync();
}
但我犯了错误,无法相应地工作。有人知道吗

未处理的异常:


System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail,System.ServiceModel,Version=2.0.5.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35]]:反序列化操作“GetHelloWorld”的请求消息体时出错。OperationFormatter遇到无效的消息正文。应找到名为“GetHelloWorld”且命名空间为“”的节点类型“Element”。找到名为“GetHelloWorldAsync”且命名空间为“

的节点类型“Element”,此时Xamarin应用程序与WCF Web服务引用连接服务提供程序为.NET标准项目(bugzilla.Xamarin.com)生成的基于任务的异步WCF代理方法不兼容

通过在Configure WCF Web Service Reference(配置WCF Web服务参考)屏幕上选中“Generate Synchronous Operations”(生成同步操作)复选框,生成较早兼容样式的WCF代理方法:

使用web服务:

KimlikServiceReference.KPSPublicSoapClient soapClient = new KimlikServiceReference.KPSPublicSoapClient(KimlikServiceReference.KPSPublicSoapClient.EndpointConfiguration.KPSPublicSoap);
//KimlikServiceReference.TCKimlikNoDogrulaResponse response = soapClient.TCKimlikNoDogrulaAsync(TCKimlikNo, Ad, Soyad, DogumYili).Result;
bool result = soapClient.TCKimlikNoDogrula(TCKimlikNo, Ad, Soyad, DogumYili);

为什么你会直接将WCF服务连接到你的移动应用程序上,而这个应用程序压力太大,没有明显的原因,为什么不只是拥有一个轻量级的web api?你的建议是什么?我该怎么做?@Jason,那个例子正在使用android项目上的代理。我可以在.net标准PCL项目上自己做吗?我正在尝试在xaml本身上使用它。可能吗?是的。尽管使用RESTful服务会容易得多——WCF是一种怪兽,如果可能的话,我会避免使用它。
KimlikServiceReference.KPSPublicSoapClient soapClient = new KimlikServiceReference.KPSPublicSoapClient(KimlikServiceReference.KPSPublicSoapClient.EndpointConfiguration.KPSPublicSoap);
//KimlikServiceReference.TCKimlikNoDogrulaResponse response = soapClient.TCKimlikNoDogrulaAsync(TCKimlikNo, Ad, Soyad, DogumYili).Result;
bool result = soapClient.TCKimlikNoDogrula(TCKimlikNo, Ad, Soyad, DogumYili);