【发布时间】:2016-07-28 09:12:44
【问题描述】:
我们将 WCF 项目添加为服务引用。当我们配置没有安全性的通信客户端时,一切正常。
没有安全保障
<security mode="None" />
现在 UWP 应用上的 .cs 文件没有安全配置。
var binding = new NetTcpBinding(SecurityMode.None);
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
client = new ServiceReference1Client(binding, new EndpointAddress(new Uri("net.tcp://localhost:1234/ServiceReference1")));
这个在 .exe.config 中没有安全性的句子就像在 Windows 8.1 中一样工作
为 .exe.config 添加安全性
<security mode="Transport">
<transport clientCredentialType="Windows"/>
</security>
现在是具有相同安全配置的 UWP 应用上的 .cs 文件。
var binding = new NetTcpBinding(SecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
client = new ServiceReference1Client(binding, new EndpointAddress(new Uri("net.tcp://localhost:1234/ServiceReference1")));
使用安全配置运行应用程序会引发此异常:
-
例外:
System.PlatformNotSupportedException -
留言:
"SecureConnectionDuplexSession is not supported."
这里是 StrackTrace:
System.ServiceModel.Channels.FramingDuplexSessionChannel.FramingConnectionDuplexSession.CreateSession(FramingDuplexSessionChannel channel, StreamUpgradeProvider upgrade)
System.ServiceModel.Channels.FramingDuplexSessionChannel..ctor(ChannelManagerBase factory, IConnectionOrientedTransportFactorySettings settings, EndpointAddress remoteAddresss, Uri via, Boolean exposeConnectionProperty)
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel..ctor(ChannelManagerBase factory, IConnectionOrientedTransportChannelFactorySettings settings, EndpointAddress remoteAddresss, Uri via, IConnectionInitiator connectionInitiator, ConnectionPool connectionPool, Boolean exposeConnectionProperty, Boolean flowIdentity)
System.ServiceModel.Channels.ConnectionOrientedTransportChannelFactory`1.OnCreateChannel(EndpointAddress address, Uri via)
System.ServiceModel.Channels.ChannelFactoryBase`1.InternalCreateChannel(EndpointAddress address, Uri via)
System.ServiceModel.Channels.ChannelFactoryBase`1.CreateChannel(EndpointAddress address, Uri via)
System.ServiceModel.Channels.ServiceChannelFactory.ServiceChannelFactoryOverDuplexSession.CreateInnerChannelBinder(EndpointAddress to, Uri via)
System.ServiceModel.Channels.ServiceChannelFactory.CreateServiceChannel(EndpointAddress address, Uri via)
System.ServiceModel.Channels.ServiceChannelFactory.CreateChannel[TChannel](EndpointAddress address, Uri via)
System.ServiceModel.ChannelFactory`1.CreateChannel(EndpointAddress address, Uri via)
System.ServiceModel.ChannelFactory`1.CreateChannel()
System.ServiceModel.ClientBase`1.CreateChannel()
System.ServiceModel.ClientBase`1.CreateChannelInternal()
System.ServiceModel.ClientBase`1.get_Channel()
Fooooooo(String jsonRequest)
Fooooooo.<Boooooo>d__0`1.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Fooooo.<Booooo>d__5.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
Foooo.<Boooooo>d__12.MoveNext()
问题
- 我们可以做些什么来支持 WCF 即服务参考和 UWP 应用之间的安全连接。
- 目前是否支持此功能?
编辑 1
我在 .exe.config 上看到了安全性
<security mode="Transport">
<transport clientCredentialType="Windows"/>
</security>
客户端状态为 Opened,但 client.InnerChannel 抛出了 System.PlatformNotSupportedException
正如@glen-thomas 所说,我试试这个配置:
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
但在这种情况下,客户端状态处于 Faultet 并引发了此异常
-
例外:
System.ServiceModel.CommunicationObjectFaultedException -
留言:
"The communication object, System.ServiceModel.ChannelFactory1[Fooo], cannot be used for communication because it is in the Faulted state."
编辑 2
在github的dotnet\wcf页面上,我们可以看到目前不支持这个。
https://github.com/dotnet/wcf/blob/master/release-notes/SupportedFeatures-v1.0.0-rc1.md
【问题讨论】:
标签: c# wcf security win-universal-app windows-10