[UWP]UWP w/NetTCP Duplex Communication RRS feed

  • Question

  • We are building an ERP for a client, with one component being a warehousing app. Being a startup, they obviously want the latest/greatest which lead us to UWP for the warehouse side. The problem we have is, the vendor they have chosen for their rugged handheld scanners only has an SDK that works with full .Net and they don't support UWP.

    To circumvent this lack of support, I started exploring a self-hosted Windows Service that has duplex communication that would interact with the scanner, and any scan events it detects, it could send up the chain via the publish/subscribe model. The problem with this approach though, is UWP doesn't appear to support duplex communication with WCF (via System.ServiceModel).

    This app will never hit the App Store because it is strictly internal, so what options might I have here? I saw one person found that they could change the scanner to Serial and then poll it for "anything scanned?" type stuff (serial mode for theirs doesn't support any events, such as "barcode scanned"), but it seems extremely backward to go that route. Is there a way to get UWP to have the same capabilities as a WPF app and/or at least get it to talk to a duplex service like this? I'm trying hard to not have to go to WPF, but I'm not sure I'll have a choice at this point. 

    Any suggestions help, but I can say no code has been posted because I don't have any issues with the NetTCP/WCF side of things - it works great, but UWP seemingly has no support for this. 


    Tuesday, January 22, 2019 9:12 PM

All replies

  • Hi,

    According to my research, it seems that System.ServiceModel.Duplex is available in UWP apps. This is mentioned here in the GitHub:"It's a subset of the .NET Framework version of Windows Communication Foundation and currently supports the same API surface available for Windows 8.1 Store apps. It is used to build .NET Core apps, including Windows UWP and ASP.NET 5. These client libraries are suitable for mobile devices or on mid-tier servers to communicate with existing WCF services." You could get more information about WCF in GitHub: dotnet/wcf.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 23, 2019 8:40 AM
  • Thanks Roy! That lead me down a path to find System.ServiceModel.DuplexClientBase, however the problem I am running into with that is every time I run the UWP app and try to connect to the proxy, I get this:

    System.PlatformNotSupportedException: Configuration files are not supported.
       at System.ServiceModel.ClientBase`1..ctor()
       at System.ServiceModel.DuplexClientBase`1..ctor(InstanceContext callbackInstance, String endpointConfigurationName, String remoteAddress)
       at UniversalClient.Scanner.ScannerProxy..ctor(InstanceContext callback)
       at UniversalClient.MainPage.Button_Click(Object sender, RoutedEventArgs e)

    The base ServiceContract looks like this:

    [ServiceContract(CallbackContract = typeof(IScannerCallback), Name = "ScannerCallback", SessionMode = SessionMode.Required)]
    	public interface IScannerSvc
    		/// <summary>
    		/// Subscribes a client to the scale publishing interface.
    		/// </summary>
    		/// <param name="computerName">The name of the computer subscribing to the scale service. This is for logging purposes.</param>
    		void Subscribe(string computerName);
    		/// <summary>
    		/// Unsubscribes a client from the scale publishing interface.
    		/// </summary>
    		bool Unsubscribe();

    The callback contract is as basic as it gets:

    public interface IScannerCallback
    		/// <summary>
    		/// Publishes the weight to the clients who are currently
    		/// connected and listening for a weight notification.
    		/// </summary>
    		/// <param name="weight">The weight to publish.</param>
    		/// <remarks>
    		/// The important attribute is the "IsOneWay" mechanism as the
    		/// server is publishing to the client(s) and does not require
    		/// a response back.
    		/// </remarks>
    		[OperationContract(IsOneWay = true)]
    		void PublishBarcode(double weight);

    Lastly, the Proxy class (inherits from DuplexClientBase) is below and as soon as I try to create a new instance of ScannerProxy, I get the error referenced above. Here's it's implementation of IScannerSvc from above:

    public class ScannerProxy : DuplexClientBase<IScannerSvc>, IScannerSvc
    		public ScannerProxy(InstanceContext callback)
    			//: base(callback)
    			: base(callback, new NetTcpBinding(SecurityMode.None), new EndpointAddress("net.tcp://localhost:50000/ScannerPublisher"))
    			this.Endpoint.Address = new EndpointAddress("net.tcp://localhost:50000/ScannerPublisher");
    		public void Subscribe(string computerName)
    		public bool Unsubscribe()
    			return base.Channel.Unsubscribe();

    Any suggestions? I feel like it's SO close, but since I'm not using configuration files anywhere, I have no idea why I get an error like that. 

    Saturday, January 26, 2019 7:03 PM
  • Hi Scott,

    There are a number of issues that I can see with your current approach. First and foremost, if I understand your architecture you are calling .net APIs provided by the scanner OEM from a Windows Service and then trying to shuttle the data back to the UWP app via WCF. You need to confirm with the scanner manufacturer that calling their APIs from a service is supported. There are a number of different HW based APIs that cannot be called from a service for various reasons. So again before committing to your current architecture check with the OEM.

    Next, have you tried calling the .net API supplied by the OEM from your UWP app? If you only intend to sideload the app and don't need it in the store you have a lot more latitude with what APIs you can call. That said, your UWP app is still running in a container and this may not allow the necessary access to the underlying hardware. This really depends on how the OEM has implemented the communications with the underlying hardware. 

    Also, is there a particular reason for using WCF? WCF is a bit of an afterthought as the Universal APIs were initially released with no support for WCF. Have you tried using the HTTP client and calling simple rest APIs for the inter-process communications? This is probably the approach I would take.

    Finally, since you are just side loading the app you might want to look at creating a hybrid Centennial app. The centennial app model allows you to use as much Win32 and UWP as needed to get your app functioning. While still running in a container it should also allow your app to get "full trust" giving the OEM's APIs the ability to interact with the underlying HW. I haven't tested a hybrid app that needs unfettered access to HW so I'm speculating a bit that this would work. 

    I hope this helps,


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Monday, January 28, 2019 6:49 PM