Xamarin.Forms WCF端点没有监听

时间:2017-03-15 11:14:32

标签: c# wcf xamarin.forms

我们制作了一个Xamarin表单应用程序并尝试连接到已经存在的外部WCF主机,我们可以在浏览器中访问它,但不能使用我们的应用程序。我们在webhost的应用程序中提供了服务引用。 这是我们得到的错误: error we get

这是我们主页的代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using xxx.xxxWCF;
using System.ServiceModel;

namespace xxx
{
    public partial class MainPage : ContentPage
    {

        public static readonly EndpointAddress EndPoint = new EndpointAddress("http://www.xxxx.xxx.be/wcf/xxxservice.svc");
        private xxxClient _client;

        public MainPage()
        {
            InitializeComponent();

            InitializeHelloWorldServiceClient();

        }


        private void InitializeHelloWorldServiceClient()
        {

            //    BasicHttpBinding binding = CreateBasicHttp();

            _client = new xxxClient(new BasicHttpBinding(), new EndpointAddress("http://www.labyt.xxx.be/wcf/xxxservice.svc"));

            _client.InloggenVoorAndroidCompleted += InloggenVoorAndroidToCompleted;



        }
//this is a click event from a button we created on the mainpage
        private void InloggenVoorAndroid(object sender, EventArgs eventArgs)
        {

            _client.InloggenVoorAndroidAsync("username", "password");


        }
        private void InloggenVoorAndroidToCompleted(object sender, InloggenVoorAndroidCompletedEventArgs inloggenVoorAndroidCompletedEventArgs)
        {


            string msg = null;

            if (inloggenVoorAndroidCompletedEventArgs.Error != null)
            {
                msg = inloggenVoorAndroidCompletedEventArgs.Error.Message;
            }
            else if (inloggenVoorAndroidCompletedEventArgs.Cancelled)
            {
                msg = "Request was cancelled.";
            }
            else
            {
                msg = inloggenVoorAndroidCompletedEventArgs.Result.username;
            }
            Xamarin.Forms.Device.BeginInvokeOnMainThread(() => labelNaam.Text = msg);

        }
        private static BasicHttpBinding CreateBasicHttp()
        {
            BasicHttpBinding binding = new BasicHttpBinding()
            {

                Name = "basicHttpBinding",
                MaxBufferSize = 2147483647,
                Namespace = "xxxService.IService",
                MaxReceivedMessageSize = 2147483647
            };

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

0 个答案:

没有答案