通用应用程序中的 WCF 客户端
WCF client in a universal app
是否可以从通用应用程序调用 WCF 服务?
我添加了一个服务引用,代理生成得很好。
但是当以编程方式创建 NetTcpBinding 并将其传递给代理的构造函数时,服务模型会抛出异常 PlatformNotSupported。
运行 模拟器和本地机器上的应用程序都生成相同的异常。
An exception of type 'System.PlatformNotSupportedException' occurred
in System.Private.ServiceModel.dll but was not handled in 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);
有人有在 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>
是的,这是可能的。这就是我在不久前做的示例应用程序中的连接方式:
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
,顺便说一下。
是否可以从通用应用程序调用 WCF 服务?
我添加了一个服务引用,代理生成得很好。 但是当以编程方式创建 NetTcpBinding 并将其传递给代理的构造函数时,服务模型会抛出异常 PlatformNotSupported。
运行 模拟器和本地机器上的应用程序都生成相同的异常。
An exception of type 'System.PlatformNotSupportedException' occurred in System.Private.ServiceModel.dll but was not handled in 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);
有人有在 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>
是的,这是可能的。这就是我在不久前做的示例应用程序中的连接方式:
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
,顺便说一下。