是否可以从通用应用程序调用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可以正常工作。 所以我想最好改一下这个问题。 是否可以在通用应用程序中创建双工 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>
答案 0 :(得分: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...
}
我使用了添加对服务的引用时生成的配置文件中的绑定。
这就是应用程序的样子。最前沿的东西....:O)
https://www.youtube.com/watch?v=YSg6hZn1DpE
顺便说一句,服务本身在WebRole
Azure
上运行。