在C#android应用程序中调用wcf服务

问题描述:

我有一个wcf服务,可以从我的azure数据库中获取完美的工作信息。唯一的问题是我在最近两天被调用这个wcf来获取信息到Android应用程序。有人可以帮助我,因为这是一个项目的一部分,需要尽快完成吗?



我一直在xamarins网站上关注本教程,但我似乎无法掌握它:与WCF合作演练





这是我的c#安卓代码:



I have a wcf service to get information from my azure database with works perfectly. Only thing is I have been stuck from the last two days calling the this wcf to get information into an android app. Can someone please help me as this is part of a project which needs to be done asap?

I have been following this tutorial on xamarins website but I can't seem to get the hang of it: Walkthrough working with WCF


Here is my c# android code:

        private SearchView _searchView;
        private ListView _listView;
        private ArrayAdapter _adapter;
        private DataTransferProcClient _client;
        public static readonly EndpointAddress EndPoint = new EndpointAddress("http://192.168.1.1:3190/DataTransferProcClient.svc");

        #region onCreate
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Load the UI defined in Location.axml
            SetContentView(Resource.Layout.location);

            InitializeDataCounty();

        }

private void InitializeDataCounty()
        {
            BasicHttpBinding binding = CreateBasicHttp();
            _client = new DataTransferProcClient(binding, EndPoint);
            _client.GetCountiesDataCompleted += ClientOnDataTransferProcCompleted;

        }

        private static BasicHttpBinding CreateBasicHttp()
        {
            BasicHttpBinding binding = new BasicHttpBinding
            {
                Name = "basicHttpBinding",
                MaxBufferSize = 2147483647,
                MaxReceivedMessageSize = 2147483647
            };

            TimeSpan timeout = new TimeSpan(0, 0, 30);
            binding.SendTimeout = timeout;
            binding.OpenTimeout = timeout;
            binding.ReceiveTimeout = timeout;
            return binding;
        }

        private void ClientOnDataTransferProcCompleted(object sender, GetCountiesDataCompletedEventArgs getCountiesDataCompletedEventArgs)
        {
            string msg = null;

            if (getCountiesDataCompletedEventArgs.Error != null)
            {
                msg = getCountiesDataCompletedEventArgs.Error.Message;
            }
            else if (getCountiesDataCompletedEventArgs.Cancelled)
            {
                msg = "Request was cancelled.";
            }
            else
            {
                msg = getCountiesDataCompletedEventArgs.Result.ToString();
            }
            RunOnUiThread(() => msg);
        }





谢谢



Thanks