C# 如何在Windows Universal App中使用双工wcf服务
如何在Windows universal app中使用双工合约的wcf服务 我正在获取C# 如何在Windows Universal App中使用双工wcf服务,c#,wcf,windows-10,uwp,nettcpbinding,C#,Wcf,Windows 10,Uwp,Nettcpbinding,如何在Windows universal app中使用双工合约的wcf服务 我正在获取PlatformNotSupportedExcetpion:此平台不支持操作。尝试使用Windows Universal App中的双工wcf服务时,运行时异常,目标为Windows 10(10.0;Build 10240) 根据API的支持 如果不可能,我应该如何继续我的场景?我有两个应用程序(控制台和windows universal xaml应用程序)在同一台机器上运行,我需要双向通信 我有clasic.
PlatformNotSupportedExcetpion:此平台不支持操作。
尝试使用Windows Universal App中的双工wcf服务时,运行时异常,目标为Windows 10(10.0;Build 10240)
根据API的支持
如果不可能,我应该如何继续我的场景?我有两个应用程序(控制台和windows universal xaml应用程序)在同一台机器上运行,我需要双向通信
我有clasic.net 4.6控制台应用程序,用于创建服务主机:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:8008/MyService"));
var binding = new NetTcpBinding(); //I've also tried net http binding
binding.Security.Mode = SecurityMode.None;
host.Description.Behaviors.Add(new ServiceMetadataBehavior());
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexTcpBinding(),
"mex");
host.AddServiceEndpoint(typeof(IMyService), binding, "");
host.Open();
服务合同:
[ServiceContract(CallbackContract = typeof(IMyServiceCallback))]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void Initialize();
}
public interface IMyServiceCallback
{
[OperationContract(IsOneWay = true)]
void OnFrame(int i);
}
我通过添加服务参考对话框尝试了ChannelFactory和生成wcf客户端,并在in-UWP应用程序中尝试了NetHttpBinding
和NetCpBinding
当我尝试创建wcf客户端实例时,它抛出PlatformNotSupportedExcetpion
来源:System.Private.ServiceModel
堆栈跟踪:
at System.ServiceModel.ReflectionExtensions.GetInterfaceMap(Type type, Type interfaceType)
at System.ServiceModel.Description.TypeLoader.GetIOperationBehaviorAttributesFromType(OperationDescription opDesc, Type targetIface, Type implType)
at System.ServiceModel.Description.TypeLoader.<>c__DisplayClass8.<AddBehaviorsFromImplementationType>b__10(Type currentType, KeyedByTypeCollection`1 behaviors)
at System.ServiceModel.Description.TypeLoader.AddBehaviorsAtOneScope[IBehavior,TBehaviorCollection](Type type, TBehaviorCollection descriptionBehaviors, ServiceInheritanceCallback`2 callback)
at System.ServiceModel.Description.TypeLoader.AddBehaviorsFromImplementationType(ServiceEndpoint serviceEndpoint, Type implementationType)
at System.ServiceModel.ChannelFactory`1.ReflectOnCallbackInstance(ServiceEndpoint endpoint)
at System.ServiceModel.ChannelFactory`1.CreateDescription()
at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address)
at System.ServiceModel.DuplexChannelFactory`1..ctor(Object callbackObject, Binding binding, EndpointAddress remoteAddress)
at System.ServiceModel.ClientBase`1..ctor(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress)
at System.ServiceModel.DuplexClientBase`1..ctor(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress)
at App1.ServiceReference1.MyServiceClientBase..ctor(InstanceContext callbackInstance)
at App1.ServiceReference1.MyServiceClient..ctor(MyServiceClientCallback callbackImpl)
at App1.ServiceReference1.MyServiceClient..ctor()
at App1.MainPage.<button_Click>d__1.MoveNext()
位于System.ServiceModel.ReflectionExtensions.GetInterfaceMap(类型类型,类型interfaceType)
位于System.ServiceModel.Description.TypeLoader.GetIOperationBehaviorAttributesFromType(操作说明opDesc,类型TargetFace,类型implType)
在System.ServiceModel.Description.TypeLoader.c__显示Class8.b__10(键入currentType,键入ByTypeCollection`1行为)
位于System.ServiceModel.Description.TypeLoader.AddBehaviorsAtOneScope[IBehavior,TBehaviorCollection](类型类型,TBehaviorCollection描述行为,ServiceInheritanceCallback`2回调)
位于System.ServiceModel.Description.TypeLoader.AddBehaviorsFromImplementationType(ServiceEndpoint ServiceEndpoint,类型implementationType)
位于System.ServiceModel.ChannelFactory`1.ReflectnCallbackInstance(ServiceEndpoint)
位于System.ServiceModel.ChannelFactory`1.CreateDescription()
位于System.ServiceModel.ChannelFactory.InitializeEndpoint(绑定绑定,端点地址)
位于System.ServiceModel.DuplexChannelFactory`1..ctor(对象回调对象、绑定绑定、EndpointAddress remoteAddress)
位于System.ServiceModel.ClientBase`1..ctor(InstanceContext回调实例、绑定绑定、EndpointAddress remoteAddress)
位于System.ServiceModel.DuplexClientBase`1..ctor(InstanceContext回调实例、绑定绑定、EndpointAddress remoteAddress)
在App1.ServiceReference1.MyServiceClientBase..ctor(InstanceContext callbackInstance)
在App1.ServiceReference1.MyServiceClient..ctor(MyServiceClient回调回调impl)
在App1.servicerence1.MyServiceClient..ctor()处
在App1.MainPage.d__1.MoveNext()中
即使在10580版本(最新的.NETCore v5.1.0)中也不支持双工方案
GitHub报告了一个错误,关于WCF双工实现中反射的错误使用。此错误已在.net core的最新版本中修复,您可以包括来自Nuget gallery的。但是,此软件包要求您还包括System.Runtime和System.Threading的预发布版本
希望能有所帮助,上个月刚刚发布了稳定版本的WCF,作为.NET Core 1.0的一部分。通过引用UWP项目的project.json文件中包的5.2.2版本,现在可以在Windows Universal Apps中支持Duplex和许多其他应用程序。我有一个UWP客户端应用程序,该应用程序在连接到Duplex
net.tcp
WCF服务时运行良好。迁移到Windows10后,我从头开始重新创建了该项目,现在我得到了完全相同的平台NotSupportedException
。在这个特定的解决方案中,我有23个项目。除新创建的UWP项目外,所有这些项目都使用AnyCPU
平台,该项目只接受/允许x86
或x64
平台,但不接受AnyCPU
。所以,我想这就是问题的根源。我试图手动添加AnyCPU
来处理项目文件。。。。当然,这并不顺利。同样,在Windows8.1下,这一功能也可以正常工作。UWP项目模板可能存在一些问题或类似的问题。另一个线程中的某个人指出了这一点。移除CallbackContract属性后,UWP客户端可以创建连接,这样基本WCF就可以工作了。然后,他陷入了在UWP中创建双工WCF客户机的困境——同样的问题。