平臺:Xamarin工作室4Xamarin WCF在釋放模式失敗
目標移動:安卓
我有一個Android應用程序調用使用basicHttpBinding的,我一直在努力使用Xamarin工作室4這是一個WCF服務在調試模式下運行完美。爲了簡化問題,我正在調用WCF的「Hello World」函數。沒有輸入參數,只有一個字符串輸出。
在調試模式下,我得到「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是通過使用工具SLsvcUtil.exe針對Web服務的.svc文件創建的.cs文件。我不確定這是否與此有關,但想要記錄下來以防萬一。
有沒有人有任何建議或看到這之前它在「調試模式」運行良好,但在「發佈模式」失敗?
謝謝!
端點是在類的變量也就是私有靜態只讀的EndpointAddress端點=新的EndpointAddress( 「XXXXX」);其中xxxxx指向我們的http://xxx.xxx.xxx/*.svc文件。 – manrysj
有時,由於Xamarin的鏈接功能,發佈模式下的WCF反序列化也可能失敗。 http://forums.xamarin.com/discussion/15531/wcf-fails-in-release-mode –