Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Unable to use WCF within Android app

ScottNimrodScottNimrod USMember ✭✭
edited August 2015 in Xamarin.Forms

I receive the following exception when attempting to invoke a WCF service within my Droid project:

"Operation is not valid due to the current state of the object"

I am not sure what I am doing wrong.
1. I wait on my Open event before I perform a RPC (remote procedure call).
2. I want until my RPC is completed before I attempt to close my connection.

public class EmailClient : IEmailClient
    FasadeClient _client = null;

    public void Send(string title, string fromAddress, string toAddress, string content)

        var message = new Messaging.Message()
            Subject = title,
            From = fromAddress,
            To = toAddress,
            Body = content

        _client.OpenCompleted += (se, ev) => _client.SendEmailAsync(message, true);
        _client.SendEmailCompleted += (se, ev) => Deactivate();

    void Activate()
        var binding = CreateBasicHttp();
        var endpoint = new EndpointAddress(@"");

        _client = new FasadeClient(binding, endpoint);

    void Deactivate() => _client.Close();

    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;


Sign In or Register to comment.