gpt4 book ai didi

android - Xamarin WCF 在 Release模式下失败

转载 作者:太空狗 更新时间:2023-10-29 15:53:52 25 4
gpt4 key购买 nike

平台:Xamarin Studio 4

目标手机:Android

我有一个使用 basicHttpBinding 调用 WCF 服务的 Android 应用程序,我一直在使用 Xamarin Studio 4 在 Debug模式下运行得很好。为了在解决此问题时简化事情,我调用了 WCF 的“Hello World”函数。没有输入参数,只有一个字符串输出。

在 Debug模式下,我收到“Hello World”响应。当我将应用程序构建切换为“发布”并再次运行应用程序时,我收到以下错误消息:

System.ServiceModel.EndpointNoFoundException: A system exception has occured. ---> System.Net.WebException: Error: ConnectFailure (No route to host) ---> System.Net.Sockets.SocketExcpetion: No route to host at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in filename unknown: 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;
});
}

BTSMobileWcfClient 是一个 .cs 文件,通过使用工具 SLsvcUtil.exe 针对 Web 服务的 .svc 文件创建。我不确定这是否与此有关,但想记录下来以防万一。

在“ Debug模式”下运行良好但在“ Release模式”下运行失败之前,有没有人有任何建议或见过这个?

谢谢!

最佳答案

我刚刚在项目的发布编译中遇到了同样的问题。在四处闲逛一段时间后,我在 ProjectOptions->AndroidApplication->Required permissions(在 Xamarin studio 中)中设置了互联网权限。它看起来对我有用

关于android - Xamarin WCF 在 Release模式下失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18832534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com