How to consume duplex wcf service in Windows Universal App
Asked Answered
G

2

6

How can I consume wcf service with duplex contract in Windows universal app?

I'm getting PlatformNotSupportedExcetpion: Operation is not supported on this platform. runtime exception when trying to consume duplex wcf service in Windows Universal App, targeting Windows 10 (10.0; Build 10240)

According msdn it is supported API.

If it is not possible, how should I proceed in my scenario? I have two applications (console and windows universal xaml app) running on the same machine and I need two-way communication.

I have clasic .net 4.6 console app, that create the service host:

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();

service contract:

[ServiceContract(CallbackContract = typeof(IMyServiceCallback))]
public interface IMyService
{
    [OperationContract(IsOneWay = true)]
    void Initialize();
}

public interface IMyServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void OnFrame(int i);
}

I have tried both, ChannelFactory and generated wcf client by Add Service Reference dialog and both NetHttpBinding and NetTcpBinding in the in UWP app.

When I try to create instance of the wcf client, it throws the PlatformNotSupportedExcetpion.

Source: System.Private.ServiceModel

StackTrace:

 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()
Gromyko answered 15/10, 2015 at 10:47 Comment(4)
I have a UWP client app that used to work perfectly well connecting to a duplex net.tcp WCF service. I re-created the project from scratch after migrating to Windows10 and now i get the very same PlatformNotSupportedException.Pennebaker
I have 23 projects within this particular solution. All of them using AnyCPU platform, except the newly created UWP project, that only accepts/allows x86 or x64 platforms, but not AnyCPU. So, i guess that's where the problem is coming from. I tried to mess with project files adding AnyCPU manually.... but that didn't go well, of course. And again, this used to work with no problem under Windows 8.1. There may be some issue with the UWP project template or something of that nature.Pennebaker
Someone in another thread noted that. After removing the CallbackContract attribute the UWP client could create a connection, so basic WCF works. Then he got stuck with creating a duplex WCF client in a UWPProsody
social.msdn.microsoft.com/Forums/windowsapps/en-US/… the same issue.Dilisio
T
1

Duplex scenario is not supported even in the 10580 build (latest .NETCore v5.1.0).

There was a bug reported ion GitHub about the wrong usage of reflection in WCF duplex implementation. This bug was fixed in the latest build for .net core and you can include the individual package from Nuget gallery. However, this package require you to also include the prerelease versions of System.Runtime and System.Threading.

enter image description here

Hope it helps,

Tradein answered 25/4, 2016 at 18:29 Comment(0)
B
4

Stable versions of WCF as part of .NET Core 1.0 was just released last month. Duplex and many other WCF features can now be supported in Windows Universal Apps by referencing the 5.2.2 version of Microsoft.NETCore.UniversalWindowsPlatform package in the project.json file of a UWP project.

Bombsight answered 29/7, 2016 at 2:55 Comment(0)
T
1

Duplex scenario is not supported even in the 10580 build (latest .NETCore v5.1.0).

There was a bug reported ion GitHub about the wrong usage of reflection in WCF duplex implementation. This bug was fixed in the latest build for .net core and you can include the individual package from Nuget gallery. However, this package require you to also include the prerelease versions of System.Runtime and System.Threading.

enter image description here

Hope it helps,

Tradein answered 25/4, 2016 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.