c#,Xamarin:执行webRequest.GetResponse()失败

时间:2015-10-13 17:05:50

标签: c# events soap xamarin

我创建了一个SoapClient类,它创建了发送简单get和post请求的基本功能。但是,输出只会产生“宾果”。并且' System.Net.WebAsyncResult',之后在SoapCLient的showDef函数中不再继续。可能是什么问题呢?在此先感谢... :)

SoapClient类

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Xml;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace Dictionaryv3
{
    [Activity (Label = "Dictionary", MainLauncher = true, Icon = "@drawable/icon")]
    public class LookUpActivity : Activity
    {

        private Button LookUp;
        private EditText Input;
        private ListView WordView;
        private List<Word> Words = new List<Word>();
        private Button Menu;
        private SoapClient client;


        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView( Resource.Layout.Main);

            LookUp = ( Button ) FindViewById ( Resource.Id.lookup);
            Input = (EditText)FindViewById (Resource.Id.input);
            WordView = (ListView)FindViewById (Resource.Id.words);
            Menu = (Button)FindViewById (Resource.Id.menu);
            client = new SoapClient ();
            client.responseReady += showDef;

            Menu.Click += (object sender, EventArgs e) => {
                PopupMenu menu = new PopupMenu (this, Menu);

                menu.Inflate (Resource.Menu.popup_menu);
                menu.Show ();

                menu.MenuItemClick += (object send, PopupMenu.MenuItemClickEventArgs args) => {
                    string title = args.Item.TitleFormatted.ToString();
                    if(title == "Select dictionaries") {
                        setDictionaryActivity();
                    }
                };

            };

            LookUp.Click += ( sender, eventArgs) => LookUpWord ();




        }

        private void setDictionaryActivity() {

            var intent = new Intent(this, typeof(DictionarySelectionActivity));
            StartActivity(intent);

        }



        private void LookUpWord() {

            String inp = Input.Text;
            if( inp != "") {
                client.SendGetRequest("http://services.aonaware.com/DictService/DictService.asmx", "Define", "word", inp);
            }
        }

        public void showDef(XmlDocument doc) {
            Words.Clear();
            XmlNodeList dlist = doc.GetElementsByTagName("Definition");
            for(int i=0;i!=dlist.Count;i++) {
                Word w = new Word();
                w.dictionary = dlist.Item(i).ChildNodes.Item(1).LastChild.InnerText;
                w.description = dlist.Item(i).ChildNodes.Item(2).InnerText;
                Words.Add(w);
            }

            WordView.Adapter = new WordAdapter(this, Words);
        }

        protected override void OnPause() {
            base.OnPause ();
        }

        protected override void OnResume() {
            LookUpWord ();
            base.OnResume ();
        }


    }
}

LookUpActivity

{{1}}

0 个答案:

没有答案