【发布时间】:2015-10-09 21:00:44
【问题描述】:
是否可以从通用应用程序调用 WCF 服务?
我添加了一个服务引用,并且代理生成得很好。 但是,当以编程方式创建 NetTcpBinding 并将其传递给代理的构造函数时,服务模型会抛出异常 PlatformNotSupported。
在模拟器和本地机器上运行应用程序都会产生相同的异常。
发生“System.PlatformNotSupportedException”类型的异常 在 System.Private.ServiceModel.dll 中但未在用户代码中处理
“不支持此操作”
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);
有人有 UAP 中工作 WCF 客户端的示例吗?
编辑
这与服务是双工服务有关!
原始合同:
[ServiceContract(CallbackContract = typeof(IPublishCallback))]
public interface IPublish { }
删除 CallbackContract 属性后,UAP 客户端可以创建连接,因此基本的 WCF 可以正常工作。 所以我想最好改写这个问题。 是否可以在通用应用程序中创建 duplex WCF 客户端?
编辑主机的服务模型
<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>
【问题讨论】:
-
应该可以,我已经在我的应用程序中完成了(虽然没有向代理构造函数传递任何东西,所以可能不适用)。
-
这是在 Windows 10 UWP 应用程序中吗?
标签: c# .net wcf win-universal-app