2017-02-23 82 views
0

我怎樣才能瞭解是否有.NETStandard API實際上是實現/支持Xamarin.Android?我在.NETStandard1.4庫中實現了一個WCF net.tcp客戶端。我從Xamarin.Android應用程序引用此庫並嘗試調用客戶端方法。 它編譯罰款,但拋出的客戶端方法調用NotImplementedException什麼.NETStandard的的API在Xamarin.Android實際執行?

因此可以說,它是,那Xamarin.Android沒有實現部分API,但仍然是「支持」 .NETStandard1.4?林問,因爲我不是能找到什麼說,它不支持,所有的類/方法,我想使用Xamarins在線實況(例如,https://developer.xamarin.com/api/type/System.ServiceModel.ClientBase%3CTChannel%3E/),並沒有提及「未實現」的記錄,但我得到了NotImplementedException。目前我無法確定它是否真的不被支持,或者是否有某些東西與我的安裝/項目混淆。

如果是,那麼.NETStandard庫的目的究竟是什麼,如果任何人只是聲稱支持它,並拋出NotImplementedException

出於完整性:

Xamarin.Android應用:

// MainActivity.cs 
using Android.App; 
using Android.Widget; 
using Android.OS; 
using System.ServiceModel; 

namespace App1 
{ 
    [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")] 
    public class MainActivity : Activity 
    { 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      // Set our view from the "main" layout resource 
      // SetContentView (Resource.Layout.Main); 
      var endpoint = new EndpointAddress("net.tcp://192.168.192.189:8550/iQOSApp_AppService"); 
      var binding = new NetTcpBinding(SecurityMode.None); 
      var client = new iQOSApp.Clients.AppContractClient(binding, endpoint); 
      int n = client.GetData(0); // NotImplementedException 
     } 
    } 
} 

.NETStandard庫:

// Clients.cs 
//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:4.0.30319.42000 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

namespace iQOSApp.Clients 
{ 


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName = "iQOSApp.Clients.IAppContract")] 
    public interface IAppContract 
    { 

     [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IAppContract/GetData", ReplyAction = "http://tempuri.org/IAppContract/GetDataResponse")] 
     int GetData(int value); 

     [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IAppContract/GetData", ReplyAction = "http://tempuri.org/IAppContract/GetDataResponse")] 
     System.Threading.Tasks.Task<int> GetDataAsync(int value); 
    } 

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    public interface IAppContractChannel : iQOSApp.Clients.IAppContract, System.ServiceModel.IClientChannel 
    { 
    } 

    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] 
    public partial class AppContractClient : System.ServiceModel.ClientBase<iQOSApp.Clients.IAppContract>, iQOSApp.Clients.IAppContract 
    { 

     public AppContractClient() 
     { 
     } 

     public AppContractClient(string endpointConfigurationName) : 
       base(endpointConfigurationName) 
     { 
     } 

     public AppContractClient(string endpointConfigurationName, string remoteAddress) : 
       base(endpointConfigurationName, remoteAddress) 
     { 
     } 

     public AppContractClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
       base(endpointConfigurationName, remoteAddress) 
     { 
     } 

     public AppContractClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
       base(binding, remoteAddress) 
     { 
     } 

     public int GetData(int value) 
     { 
      return base.Channel.GetData(value); 
     } 

     public System.Threading.Tasks.Task<int> GetDataAsync(int value) 
     { 
      return base.Channel.GetDataAsync(value); 
     } 
    } 
} 
+0

我忘了提,我使用VS 2017年RC – ArgusMagnus

+0

您可以嘗試升級到最新的Cycle 9發行版(今天剛剛發佈)以查看此問題是否已得到解決,但一般來說,Xamarin平臺上的.NET標準支持尚不可靠。它只有在.NET Core 2.0可用時纔可以完全工作。 –

+0

您可以說一旦Xamarin完全支持.NET Core 2.0的可能性嗎? – ArgusMagnus

回答

1

因此可以說,它是,那Xamarin.Android沒有實現部分API,但仍「支持」.NETStandard1.4?

是的,這是正確的。實際上,有很多舊平臺會在沒有實現的領域拋出NIE(未實現例外)。這更多的是一種單聲道兼容性的事情:http://www.mono-project.com/docs/about-mono/compatibility/

你可以實現你自己的平臺,並拋出PlatformNotSupportedException在你的實現,它會被認爲是「支持netstandard」。亞倫護士已經在這裏就是一個很好的啓示:https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7#gistcomment-1759645

因此,你最有可能運行到Mono的WCF堆棧的問題缺少某些功能:

http://www.mono-project.com/docs/web/wcf/

一般來說,Xamarin平臺支持與Silverlight運行時一起提供的WCF的相同客戶端子集。這包括使用BasicHttpBinding類的HTTP傳輸協議中WCF最常見的編碼和協議實現 - 文本編碼的SOAP消息。另外,WCF支持需要使用僅在Windows環境中可用的工具來生成代理。

https://developer.xamarin.com/guides/xamarin-forms/web-services/consuming/wcf/

注:要小心了Xamarin文檔的某些類型。它們直接從MSDN中取出,並不意味着如果它在BCL中列出,則所有內容都受支持。爲了更精確地裝配列表,請參閱:

https://developer.xamarin.com/guides/cross-platform/advanced/available-assemblies/

你是最好看的Silverlight MSDN文檔:https://msdn.microsoft.com/en-us/library/system.servicemodel(v=vs.95).aspx

+0

第一段可能是錯誤的。許多平臺應該像[這裏](https://github.com/dotnet/standard/blob/master/docs/faq.md)所述的那樣拋出'PlatformNotSupportedException',而不是'NotImplementedException'。 –

+0

@LexLi是的你是對的。我只是試圖解釋WRT mono的概念:http://www.mono-project.com/docs/about-mono/compatibility/我會編輯更有意義。 –

+0

我嘗試使用SlSvcUtil.exe生成兼容Silverlight的客戶端,但引發了完全相同的異常。無論如何,你回答了我的問題,謝謝。 – ArgusMagnus

相關問題