Xamarin的Andr​​oid的问题,并与Web服务时的问题(SOAP .NET 2.0) [英] Xamarin Android Questions and Issues when working with WebServices (SOAP .NET 2.0)

查看:485
本文介绍了Xamarin的Andr​​oid的问题,并与Web服务时的问题(SOAP .NET 2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直与Xamarin和Web服务(规定为2.0 .NET中的Webservice Xamarin)在过去的几个星期。我已经拼命地跑入了一些问题,我想不出一个解决办法呢。

I've been working with Xamarin and Webservices (Stated as .NET 2.0 Webservice in Xamarin) in the past few weeks. And I've runned into a few problems that I couldn't figure a workaround yet.

1)如何设置web服务超时?无论价值的超时属性被忽略。我相信,所使用的默认值是30秒左右的东西。但我想5秒~~

1st) How do I set a timeout for the webservice? The Timeout property is ignored regardless of its value. I believe the default being used is something around 30 seconds. But I'd like 5 seconds~~.

2日)当WebService调用任何方法异步,使用开始。反正是有检查异步方法是否正确完成或已超时?我得到了检查的唯一方法是通过在End方法perfoming一个try / catch。如果是因超时而解雇,这将引发异常。但我不知道是否有某种属性或方法的地方,会告诉我,如果Web服务调用没有超时或正确处理。这里所使用的Web服务方法的IsAlive。

2nd) When the WebService call any method async, using the Begin. Is there anyway to check whether the async method was completed correctly or was timed out? The only way I got to "check" is by perfoming a try/catch in the End method. If it was fired because of a timeout, it will raise an exception. But I wonder if there is some property or method somewhere that would tell me if the webservice call did timeout or was processed correctly. The webservice method being used here is "IsAlive".

WebService.MainService.BeginIsAlive ((ar) => 
{ 
    try 
    { 
        bool result = WebService.MainService.EndIsAlive (ar); //If timedout will raise an exception. 
        RunOnUiThread (() => 
        { 
            Toast.MakeText (this, "Running as expected...", ToastLength.Long).Show();
        });

        StartActivity (typeof(OtherScreen));
    } 
    catch (Exception ex) 
    {
            //Probably timeout.
    }
}, null);

3)有没有办法来取消Web服务异步操作?如CancelIsAlive。我发现的唯一方法是Webservice.Abort。但我不相信这是最佳做法,因为它不是具体的,它可能会拧一切。

3rd) Is there a way to Cancel a webservice async operation? Such as "CancelIsAlive". The only method I found was Webservice.Abort. But I do not believe it is a best practice and since it is not specific, it may screw everything up.

在此先感谢,路易斯·恩里克。

Thanks in advance, Luís Henrique.

推荐答案

这就是我通常调用Web服务,并具有对它们的控制做的(假设你的WS功能需要一个字符串,并返回一个字符串):

That's what usually I do for calling WebServices and having control on them (assume your ws function needs an string and returns an string):

    public static void CallSomeFunction(string SomeParameter, Action<string> Ok, Action Error, Activity Context)
    {
        ThreadPool.QueueUserWorkItem ((object e) => {


            var proxy = new YourProxyClass();
            proxy.Timeout = 10000;

            try{

                var res = proxy.YourFunction(SomeParameter);
                Context.RunOnUiThread(() => Ok(res));

            }
            catch(Exception Ex){

                if(Error != null)
                    Context.RunOnUiThread(Error);

            }


        });
    }

这是我该怎么办异步任务,使用线程池进行同步调用,并通过一些操作来执行,如果一切正常或错误。我也正在传递一个上下文,所以我的好和错误操作的UI线程执行。

This is how I do asynchronous tasks, use the ThreadPool to make synchronous calls, and pass some Actions to execute if all is ok or wrong. Also I'm passing a Context so my Ok and Error actions be executed in the UI thread.

这篇关于Xamarin的Andr​​oid的问题,并与Web服务时的问题(SOAP .NET 2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆