2013-09-16 27 views
2

平台: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文件。我不确定这是否与此有关,但想要记录下来以防万一。

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

谢谢!

+0

端点是在类的变量也就是私有静态只读的EndpointAddress端点=新的EndpointAddress( “XXXXX”);其中xxxxx指向我们的http://xxx.xxx.xxx/*.svc文件。 – manrysj

+0

有时,由于Xamarin的链接功能,发布模式下的WCF反序列化也可能失败。 http://forums.xamarin.com/discussion/15531/wcf-fails-in-release-mode –

回答

5

我在编译我的项目时遇到了同样的问题。经过一段时间的漫游后,我在ProjectOptions-> AndroidApplication-> Required权限(在Xamarin studio中)设置了互联网权限。它看起来工作对我来说

+0

非常感谢你这个答案。它也适用于我。 – manrysj

0

解决方案#1:


  • 将Internet的权限
  • PorjectOptions-> Android的应用程序 - >互联网

解决方案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组件。

1

对于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" />