Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Calling a wcf from android app.

$
0
0

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. I have been following the tutorial "Walkthrough working with WCF"

I am building an android app for a festival system (MVC 4 application). This activity page populates a listview with with counties here in Ireland, and from there would drill down into towns within that county and once you select that town it'll pull out festivals from that selected town.

You may see I have an array list, this was just done to test that app, to see if I could get a populated list working with search functionality. Here is my c# android code:

using System;
using System.Net;
using System.Reflection.Emit;
using System.ServiceModel;
using Android.App;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using Java.Interop;
using Java.Text;

namespace MyFestivalApp
{
    [Activity(Label = "Search By Location", Theme = "@style/Theme.AppCompat.Light")]
    public class ByLocationActivity : ActionBarActivity
    {
        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();

            var counties = new[]
            {
                "Antrim", "Armagh", "Carlow", "Cavan", "Clare", "Cork", "Donegal", "Down","Derry",
                "Dublin", "Fermanagh", "Galway", "Kerry", "Kildare", "Kilkenny", "Laois", "Leitrim",
                "Limerick", "Longford", "Louth", "Mayo", "Meath", "Monaghan", "Offaly",
                "Roscommon", "Sligo", "Tipp", "Tyrone", "Waterford", "Westmeath", "Wexford", "Wicklow"
            };

            _listView = FindViewById<ListView>(Resource.Id.listView);
            _adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, counties);
            _listView.Adapter = _adapter;

        }
        #endregion

        #region Search List
        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Menu.search, menu);

            var item = menu.FindItem(Resource.Id.action_search);
            //var backbutton = menu.FindItem(Resource.Id.action_back);

            var searchview = MenuItemCompat.GetActionView(item);
            _searchView = searchview.JavaCast<SearchView>();

            _searchView.QueryTextChange += (s, e) => _adapter.Filter.InvokeFilter(e.NewText);

            _searchView.QueryTextSubmit += (s, e) =>
            {
                Toast.MakeText(this, "Search for: " + e.Query, ToastLength.Short).Show();
                e.Handled = true;
            };
            return true;
        }
        #endregion


        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);
        }
    }
}`

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>