I just followed "Walkthrough - Working with WCF". But I can't get any data from server.
I did make Proxy and add it to Android project here
Here is my Activity
using Android.App;
using Android.Widget;
using Android.OS;
using System;
using System.ServiceModel;
using HelloWorldServiceProxy;
using System.Runtime.Serialization;
using static Java.Util.Jar.Attributes;
namespace HelloWorld
{
[Activity(Label = "HelloWorld", MainLauncher = true)]
public class MainActivity : Activity
{
static readonly EndpointAddress Endpoint = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/HelloWorldService/?wsdl");
HelloWorldServiceClient _client;
Button _getHelloWorldDataButton;
TextView _getHelloWorldDataTextView;
Button _sayHelloWorldButton;
TextView _sayHelloWorldTextView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
InitializeHelloWorldServiceClient();
// This button will invoke the GetHelloWorldData - the method that takes a C# object as a parameter.
_getHelloWorldDataButton = FindViewById<Button>(Resource.Id.getHelloWorldDataButton);
_getHelloWorldDataButton.Click += GetHelloWorldDataButtonOnClick;
_getHelloWorldDataTextView = FindViewById<TextView>(Resource.Id.getHelloWorldDataTextView);
// This button will invoke SayHelloWorld - this method takes a simple string as a parameter.
_sayHelloWorldButton = FindViewById<Button>(Resource.Id.sayHelloWorldButton);
_sayHelloWorldButton.Click += SayHelloWorldButtonOnClick;
_sayHelloWorldTextView = FindViewById<TextView>(Resource.Id.sayHelloWorldTextView);
}
void InitializeHelloWorldServiceClient()
{
BasicHttpBinding binding = CreateBasicHttpBinding();
_client = new HelloWorldServiceClient(binding, Endpoint);
}
static BasicHttpBinding CreateBasicHttpBinding()
{
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;
}
async void GetHelloWorldDataButtonOnClick(object sender, EventArgs e)
{
var data = new HelloWorldData
{
Name = "Mr. Chad",
SayHello = true
};
_getHelloWorldDataTextView.Text = "Waiting for WCF...";
HelloWorldData result;
try
{
result = await _client.GetHelloDataAsync(data);
_getHelloWorldDataTextView.Text = result.Name;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
async void SayHelloWorldButtonOnClick(object sender, EventArgs e)
{
_sayHelloWorldTextView.Text = "Waiting for WCF...";
try
{
var result = await _client.SayHelloToAsync("Kilroy");
_sayHelloWorldTextView.Text = result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
What should I do to get data from Server...? What Did I do wrong...? Or Is there any wrong in Walkthrough?
There several issues with testing WCF on Xamarin and Andriod
There are many remedies for this, however the easiest way i found to test this, is the following (not i don not recommend leaving your firewall off)
issexpress -> show all applications, click the service, and go to the config pathExample changes
*For a more permanent solution you will need to look up how to configure your Advanced Firewall Settings.
Furthermore, accessing
LocalHoston your emulator wont work. On the Emulator Virtual machine , the LocalHost refers to the device on which the code is running (the emulator).If you want to refer to the computer which is running the Android Emulator, use the IP address
10.0.2.2instead. You can read more from here.