Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin中基于WCF任务的服务消耗_C#_Android_Wcf_Xamarin_Xamarin.android - Fatal编程技术网

C# Xamarin中基于WCF任务的服务消耗

C# Xamarin中基于WCF任务的服务消耗,c#,android,wcf,xamarin,xamarin.android,C#,Android,Wcf,Xamarin,Xamarin.android,我正在重构WPF项目以增加对android的支持,我有一个PCL项目用于使用WCF服务。同样的代码对WCF也适用,但在Android应用程序中会产生错误 服务内容如下: [ServiceContract] public interface IMessage { [OperationContract] Task<string> GetMessages(string msg); } WPF应用程序工作正常,但Android会生成一个错误: System.Runtime.

我正在重构WPF项目以增加对android的支持,我有一个PCL项目用于使用WCF服务。同样的代码对WCF也适用,但在Android应用程序中会产生错误

服务内容如下:

[ServiceContract]
public interface IMessage
{
    [OperationContract]
    Task<string> GetMessages(string msg);
}
WPF应用程序工作正常,但Android会生成一个错误:

System.Runtime.Serialization.SerializationException:
Deserializing type 'System.Threading.Tasks.Task1[[System.String, mscorlib,
Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
Expecting state 'EndElement'. Encountered state 'Text' with name '' with namespace ''. (1,141)`

你的代码错了。您不能通过导线传递
任务
。删除它并创建一个适当的服务。@HighCore此代码基于此,在WPF和Store应用程序中运行良好,mono生成异常。我猜Xamarin不支持在客户端使用任务。尝试使用开始/结束对并手动将它们包装到任务中。@StephenCleary Hi,你能演示如何作为答案吗?@MerdanGochmuradov Hi,你解决问题了吗?
public class Proxy : ClientBase<IMessage>
{
    public Proxy()
    {
    }
    public Proxy(string endpointConfigurationName) :
        base(endpointConfigurationName)
    {
    }
}
var client = new Proxy("BasicHttpBinding_IMessage");
HelloServer = "Waiting for the result";
HelloServer = await client.Channel.GetMessages(Hello);
System.Runtime.Serialization.SerializationException:
Deserializing type 'System.Threading.Tasks.Task1[[System.String, mscorlib,
Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
Expecting state 'EndElement'. Encountered state 'Text' with name '' with namespace ''. (1,141)`