平台:Xamarin Studio 4
目标手机:安卓
我有一个使用 basicHttpBinding 调用 WCF 服务的 android 应用程序,我一直在使用 Xamarin Studio 4 在调试模式下运行完美。为了在解决此问题时简化事情,我调用了 WCF 的“Hello World”函数。没有输入参数,只有一个字符串输出。
在调试模式下,我得到“Hello World”响应。当我将应用程序构建切换到“发布”并再次运行应用程序时,我收到以下错误消息:
System.ServiceModel.EndpointNoFoundException:发生系统异常。---> 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] 文件名未知: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 是使用工具 SLsvcUtil.exe 针对 Web 服务的 .svc 文件创建的 .cs 文件。我不确定这是否与此有关,但想记录下来以防万一。
在“调试模式”下运行良好但在“发布模式”下失败之前,有没有人有任何建议或看过这个?
谢谢!