2015-10-15 41 views
6

如何在Windows通用应用程序中使用具有双面合同的wcf服务? (;建立10240 10.0)如何在Windows通用应用程序中使用双工wcf服务

根据msdn它支持的API

当试图在Windows通用应用程序消耗双工WCF服务,针对Windows 10我得到PlatformNotSupportedExcetpion: Operation is not supported on this platform.运行时异常。

如果这是不可能的,我应该如何继续我的方案?我有两个应用程序(控制台和Windows通用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客户端生成对话框,并且在UWP应用程序中都有NetHttpBindingNetTcpBinding

当我尝试创建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() 
+0

我有一个UWP客户端应用程序,它可以很好地连接到双工'net.tcp' WCF服务。迁移到Windows10后,我重新创建了该项目,现在我得到了同样的'PlatformNotSupportedException'。 – jsanalytics

+0

我在这个特定的解决方案中有23个项目。除了新创建的UWP项目外,他们都使用'AnyCPU'平台,只接受/允许'x86'或'x64'平台,而不是'AnyCPU'。所以,我想这就是问题来自何处。我试图搞乱项目文件,手动添加'AnyCPU' ......但当然这并不顺利。再次,这用于在Windows 8.1下无任何问题。 UWP项目模板可能存在一些问题,或者具有这种性质。 – jsanalytics

+0

另一个线程中的人注意到这一点。在删除CallbackContract属性后,UWP客户端可以创建一个连接,所以基本的WCF工作。 然后,他陷入了在UWP –

回答

0

复式方案未在10580版本(最新.NETCore V5.1.0),甚至支持。

有一个错误报告了离子GitHub有关WCF双工实现中反射的错误用法。该错误已在.net内核的最新版本中修复,您可以在Nuget库中添加individual package。但是,此软件包要求您还包括System.Runtime和System.Threading的预发布版本。

enter image description here

希望它能帮助,

4

WCF的稳定版本为.NET 1.0核心的一部分,上个月刚刚发布。通过在UWP项目的project.json文件中引用5.2.2版本的Microsoft.NETCore.UniversalWindowsPlatform包,现在可以在Windows通用应用程序中支持双工和其他许多其他WCF features

相关问题