【问题标题】:Xamarin WCF Fails in Release ModeXamarin WCF 在发布模式下失败
【发布时间】:2013-09-16 16:05:07
【问题描述】:

平台:Xamarin Studio 4

目标手机:Android

我有一个 android 应用程序,它使用 basicHttpBinding 调用 WCF 服务,我一直在使用 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 文件。我不确定这是否与此有关,但想记录下来以防万一。

在“调试模式”下运行良好但在“发布模式”下失败之前,有没有人有任何建议或看过这个?

谢谢!

【问题讨论】:

标签: android .net wcf xamarin.android xamarin


【解决方案1】:

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

【讨论】:

  • 非常感谢您的回答。它也对我有用。
【解决方案2】:

对于 Visual Studio,在 android.manifest 中添加下一行:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

【讨论】:

    【解决方案3】:

    解决方案 #1:


    • 设置上网权限
    • PorjectOptions->Android 应用程序->Internet

    解决方案 #2:


    1. 在根目录中创建一个名为 System.ServiceModel.xml 的新文件。
    2. 将 System.ServiceModel.xml 的构建操作更改为 LinkDescription。
    3. 将以下内容添加到 System.ServiceModel.xml。

      <?xml version="1.0" encoding="utf-8" ?>
      <linker>
         <assembly fullname="System.ServiceModel">
              <type fullname="System.ServiceModel.Channels.ChannelFactoryBase`1">
                  <method name="CreateChannel" />
               </type>
          </assembly>
      </linker>
      
    4. 确保链接器设置仅设置为 SDK 程序集。

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      相关资源
      最近更新 更多