Xamarin.Android 中实际实现了 .NETStandard 的哪些 API?
What APIs of the .NETStandard are actually implemented in Xamarin.Android?
如何确定 .NETStandard API 是否实际上是 Xamarin.Android 的 implemented/supported?我有一个在 .NETStandard1.4 库中实现的 WCF net.tcp 客户端。我从 Xamarin.Android 应用程序引用此库并尝试调用客户端方法。
它编译正常,但在客户端方法调用时抛出 NotImplementedException
。
那么 Xamarin.Android 是否可以不实现一些 API 但仍然 "supports" .NETStandard1.4?我问是因为我找不到任何说它不受支持的东西,我想使用的所有 classes/methods 都记录在 Xamarins 在线文档中(例如 https://developer.xamarin.com/api/type/System.ServiceModel.ClientBase%3CTChannel%3E/),没有提到 "Not Implemented" ,但我得到 NotImplementedException
。目前我不知道它是否真的不受支持,或者我的 installation/project.
是否有问题
如果是,那么 .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
}
}
}
.NET 标准库:
// 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);
}
}
}
So can it be, that Xamarin.Android doesn't implement some APIs but still "supports" .NETStandard1.4?
是的,没错。事实上,有许多旧平台会在它们没有实现的区域抛出 NIE(未实现的异常)。这更像是一个单声道兼容性的东西:http://www.mono-project.com/docs/about-mono/compatibility/
您可以实现自己的平台并在您的所有实现中投入 PlatformNotSupportedException
,它会被视为 "Supporting netstandard
"。 Aaron Nurse 对此有很好的见解:https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7#gistcomment-1759645
因此,您很可能 运行 遇到了缺少某些功能的 Mono 的 WCF 堆栈问题:
http://www.mono-project.com/docs/web/wcf/
In general, the Xamarin platform supports the same client-side subset of WCF that ships with the Silverlight runtime. This includes the most common encoding and protocol implementations of WCF — text-encoded SOAP messages over the HTTP transport protocol using the BasicHttpBinding class. In addition, WCF support requires the use of tools only available in a Windows environment to generate the proxy.
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
如何确定 .NETStandard API 是否实际上是 Xamarin.Android 的 implemented/supported?我有一个在 .NETStandard1.4 库中实现的 WCF net.tcp 客户端。我从 Xamarin.Android 应用程序引用此库并尝试调用客户端方法。
它编译正常,但在客户端方法调用时抛出 NotImplementedException
。
那么 Xamarin.Android 是否可以不实现一些 API 但仍然 "supports" .NETStandard1.4?我问是因为我找不到任何说它不受支持的东西,我想使用的所有 classes/methods 都记录在 Xamarins 在线文档中(例如 https://developer.xamarin.com/api/type/System.ServiceModel.ClientBase%3CTChannel%3E/),没有提到 "Not Implemented" ,但我得到 NotImplementedException
。目前我不知道它是否真的不受支持,或者我的 installation/project.
如果是,那么 .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
}
}
}
.NET 标准库:
// 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);
}
}
}
So can it be, that Xamarin.Android doesn't implement some APIs but still "supports" .NETStandard1.4?
是的,没错。事实上,有许多旧平台会在它们没有实现的区域抛出 NIE(未实现的异常)。这更像是一个单声道兼容性的东西:http://www.mono-project.com/docs/about-mono/compatibility/
您可以实现自己的平台并在您的所有实现中投入 PlatformNotSupportedException
,它会被视为 "Supporting netstandard
"。 Aaron Nurse 对此有很好的见解:https://gist.github.com/davidfowl/8939f305567e1755412d6dc0b8baf1b7#gistcomment-1759645
因此,您很可能 运行 遇到了缺少某些功能的 Mono 的 WCF 堆栈问题:
http://www.mono-project.com/docs/web/wcf/
In general, the Xamarin platform supports the same client-side subset of WCF that ships with the Silverlight runtime. This includes the most common encoding and protocol implementations of WCF — text-encoded SOAP messages over the HTTP transport protocol using the BasicHttpBinding class. In addition, WCF support requires the use of tools only available in a Windows environment to generate the proxy.
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