通用应用程序中的WCF客户端

Ser*_*sen 5 .net c# wcf win-universal-app

是否可以从通用应用程序调用WCF服务?

我添加了一个服务引用,代理生成得很好.但是,当以编程方式创建NetTcpBinding并将其传递给代理的构造函数时,服务模型会抛出异常PlatformNotSupported.

在模拟器和本地计算机上运行应用程序都会生成相同的异常.

System.Private.ServiceModel.dll中发生了'System.PlatformNotSupportedException'类型的异常,但未在用户代码中处理

"不支持此操作"

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);
Run Code Online (Sandbox Code Playgroud)

有没有人在UAP中有一个工作的WCF客户端的例子?

编辑

它与服务是双工服务有关!

原合同:

[ServiceContract(CallbackContract = typeof(IPublishCallback))]
public interface IPublish { }
Run Code Online (Sandbox Code Playgroud)

删除CallbackContract属性后,UAP客户端可以创建连接,因此基本WCF可以正常工作.所以我想最好改一下这个问题.是否可以在通用应用程序中创建双工 WCF客户端?

编辑主机的servicemodel

<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>
Run Code Online (Sandbox Code Playgroud)

jsa*_*ics 0

对的,这是可能的。这就是我在不久前完成的示例应用程序中连接的方式:

 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...
            }
Run Code Online (Sandbox Code Playgroud)

我使用了添加对服务的引用时生成的配置文件中的绑定。

这就是应用程序的样子。尖端的东西......:O)

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

顺便说一下,服务本身是作为WebRoleon运行的。Azure