WCF客户端在一个通用的应用程序
本文关键字:一个 应用程序 客户端 WCF | 更新日期: 2023-09-27 18:16:45
是否有可能从通用应用程序调用WCF服务?
我添加了一个服务引用,代理生成得很好。但是,当以编程方式创建netttcpbinding并将其传递给代理的构造函数时,服务模型会抛出异常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客户端?
edit 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>
是有可能的。这是我如何连接在一个示例应用程序我做了一会儿:
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服务本身在Azure
上作为WebRole
运行。