WCF client in a universal application

Can I call the WCF service from a generic application?

I added a link to the service, and the proxy was generated just fine. But when you create NetTcpBinding programmatically and pass this proxy constructor, the service model throws a PlatformNotSupported exception.

Both application launches in the simulator and on the local computer generate the same exception.

An exception of type "System.PlatformNotSupportedException" occurred in System.Private.ServiceModel.dll, but was not processed in the user code.

"this operation is not supported"

EndpointAddress address = new EndpointAddress("net.tcp://test:9000/ServicesHost/PublishService"); NetTcpBinding binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; PublishingService.PublishClient proxy = new PublishingService.PublishClient(binding, address); 

Does anyone have an example of a working WCF client in UAP?

EDIT

This is because the service is a duplex service!

Original contract:

 [ServiceContract(CallbackContract = typeof(IPublishCallback))] public interface IPublish { } 

After removing the CallbackContract attribute, the UAP client can create a connection, so the underlying WCF works. So I think it's better to rephrase the question. Is it possible to create a duplex WCF client in a universal application?

change servicemodel for host

 <system.serviceModel> <bindings> <netTcpBinding> <binding name="netTcpPublishService" openTimeout="00:00:10" receiveTimeout="infinite"> <reliableSession inactivityTimeout="24.20:31:23.6470000" enabled="true" /> <security mode="Transport"> <transport clientCredentialType="Windows" /> </security> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="serviceBehaviour"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="serviceBehaviour" name="PublishService.Publish"> <endpoint binding="mexHttpBinding" name="mexPublishService" contract="IMetadataExchange" /> <endpoint address="PublishService" binding="netTcpBinding" bindingConfiguration="netTcpPublishService" name="netTcpPublishService" contract="PublishService.IPublish" /> <host> <baseAddresses> <add baseAddress="http://localhost:8004/ServicesHost/PublishService" /> <add baseAddress="net.tcp://localhost:9004/ServicesHost/PublishService" /> </baseAddresses> </host> </service> </services> </system.serviceModel> 
+5
source share
1 answer

Yes it is possible. Here's how I connected to the sample application I made some time ago:

  using Tradeng.Srvc.Client.WinAppSimple.SrvcRefTradeng; private InstanceContext instanceContext; private TradengSrvcClientBase serviceProxy; instanceContext = new InstanceContext(this); serviceProxy = new TradengSrvcClientBase(instanceContext); bool result = await serviceProxy.ConnectAsync(); if (result) { // connected... } 

I used the binding from the configuration file that is created when adding a link to your service.

This is what the app looks like. Advanced stuff ....: O)

https://www.youtube.com/watch?v=YSg6hZn1DpE

The service itself works like WebRole on Azure , by the way.

0
source

Source: https://habr.com/ru/post/1233155/


All Articles