簡體   English   中英

如何在Windows Universal App中使用雙工wcf服務

[英]How to consume duplex wcf service in Windows Universal App

如何在Windows通用應用程序中使用雙工合同來使用wcf服務?

我正在使用PlatformNotSupportedExcetpion: Operation is not supported on this platform. 嘗試在Windows Universal App中使用雙面wcf服務時出現運行時異常,目標是Windows 10(10.0; Build 10240)

根據msdn,它支持API。

如果不可能,我應該如何進行我的方案? 我有兩個應用程序(控制台和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);
}

我已經通過“添加服務引用”對話框以及UWP應用程序中的NetHttpBindingNetTcpBinding同時嘗試了ChannelFactory和生成的wcf客戶端。

當我嘗試創建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()

作為.NET Core 1.0的一部分,WCF的穩定版本於上個月發布。 通過在UWP項目的project.json文件中引用5.2.2版本的Microsoft.NETCore.UniversalWindowsPlatform包,現在可以在Windows Universal Apps中支持雙工和許多其他WCF功能

即使在10580版本(最新的.NETCore v5.1.0)中也不支持雙工方案。

有一個錯誤報告了離線GitHub關於WCF雙工實現中錯誤使用反射的問題。 在.net核心的最新版本中修復了此錯誤,您可以在Nuget gallery中包含單個包 但是,此程序包要求您還包括System.Runtime和System.Threading的預發布版本。

在此輸入圖像描述

希望能幫助到你,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM