6
In the event of a button of my APP had the following code it worked running on the android emulator, but when I passed the app to the mobile generates a message the app stopped.
Button buttonPessoasNecessita = FindViewById<Button> (Resource.Id.mybuttonPesNec);
buttonPessoasNecessita.Click += delegate {
Service1Client client;
var binding = new BasicHttpBinding () { Name= "basicHttpBinding", MaxReceivedMessageSize = 67108864,};
binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{ MaxArrayLength = 2147483646, MaxStringContentLength = 5242880, };
var timeout = new TimeSpan(0,60,60);
binding.SendTimeout= timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
client = new Service1Client(binding, new EndpointAddress ("http://engb.uni5.net/Service1.svc"));
buttonPessoasNecessita.text = client.envioPessoa();
};
Trying to solve the case I thought of using asynchronously, I looked for several examples but none became clear to me and I saw that my 'client' object exists a method has a beginenvioPessoa() and other endenvioPessoa(); Based on this link Easy way to use WCF service with async/await I tried to assemble a method to consume the web service async
call of the method:
var t = await executeAsync(binding);
Method:
public async Task<string> executeAsync(BasicHttpBinding binding){
Service1Client client = new Service1Client(binding, new EndpointAddress ("http://engb.uni5.net/Service1.svc"));
var t = Task<string>.Factory.FromAsync (
((IService1)client.InnerChannel).BeginenvioPessoa,
((IService1)client.InnerChannel).EndenvioPessoa);
return await t;
}
At the end my code does not work displays syntax errors
Error CS1502: The best overloaded method match for 'System.Threading.Tasks.TaskFactory.Fromasync(System.Iasyncresult, System.Func)' has some invalid Arguments (CS1502)
Error CS1503: Argument 1: cannot Convert from 'method group' to 'System.Iasyncresult' (CS1503)
In the second you should look for a
envioPessoa
that returns aTask<T>
and makeawait
before calling. But your first example should be simpler. In the first code, which error?– Vitor Canova