Xamarin WCF在发布模式下失败

man*_*ysj 2 .net wcf android xamarin.android xamarin

平台:Xamarin Studio 4

目标手机:Android

我有一个Android应用程序使用basicHttpBinding调用WCF服务,我一直在使用Xamarin Studio 4,它在调试模式下运行得非常好.为了简化这一过程,我要调用WCF的"Hello World"功能.没有输入参数,只有字符串输出.

在调试模式下,我得到"Hello World"响应.当我将应用程序构建切换到"Release",并再次运行该应用程序时,我收到以下错误消息:

System.ServiceModel.EndpointNoFoundException:发生了系统异常.---> System.Net.WebException:错误:ConnectFailure(无主机路由)---> System.Net.Sockets.SocketExcpetion:无法在System.Net.Sockets.Socket.Connect(System.Net. EndPoint remoteEP)[0x00000]在文件名未知:0

调用WCF的代码是:

BasicHttpBinding binding = CreateBasicHttp ();
BTSMobileWcfClient _client = new BTSMobileWcfClient (binding, endPoint);
_client.SayHelloCompleted += ClientOnSayHelloCompleted;
_client.SayHelloAsync();

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 ClientOnSayHelloCompleted(object sender, SayHelloCompletedEventArgs sayHelloCompletedEventArgs)
        {
            string msg = null;

            if (sayHelloCompletedEventArgs.Error != null)
            {
                msg = sayHelloCompletedEventArgs.Error.ToString();
            }
            else if (sayHelloCompletedEventArgs.Cancelled)
            {
                msg = "Request was cancelled.";
            }
            else
            {
                msg = sayHelloCompletedEventArgs.Result.ToString();
            }
            RunOnUiThread(() =>{
                var lblSignInError = FindViewById<TextView> (Resource.Id.lblSignInError);
                lblSignInError.Text = msg;
            });
        }
Run Code Online (Sandbox Code Playgroud)

BTSMobileWcfClient是使用工具SLsvcUtil.exe针对Web服务的.svc文件创建的.cs文件.我不确定这与它有什么关系,但是想要记录这个以防万一.

有没有人在"调试模式"下运行正常但在"发布模式"失败之前有任何建议或看到过这个?

谢谢!

小智 7

我刚刚在我的项目的发布编译中遇到了同样的问题.在游荡一段时间后,我在ProjectOptions-> AndroidApplication->所需权限(在Xamarin工作室中)设置了Internet权限.它看起来对我有用