有没有办法告诉WCF在请求中使用安全性,但是在响应中忽略它呢?
我们必须连接到第三方SOAP服务,并且正在使用WCF进行连接。该服务是使用Apache AXIS开发的,我们无法控制它,也没有影响更改其工作方式。
我们看到的问题是,它期望使用Web服务安全性来格式化请求,因此我们正在执行所有正确的签名等操作。但是,来自第三方的响应并不安全。如果我们嗅探电线,我们会看到响应返回正常(尽管没有任何时间戳,签名等)。
底层的.NET组件将此错误视为错误,因为它将其视为安全问题,因此我们实际上并没有收到类似的肥皂响应。有什么方法可以配置WCF框架以发送安全请求,但不能期望响应中的安全字段吗?查看OASIS规范,似乎并没有要求响应必须是安全的。
有关信息,这是我们看到的异常:
我们收到的异常是:
System.ServiceModel.Security.MessageSecurityException was caught Message="Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security." Source="mscorlib" StackTrace: Server stack trace: at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessageCore(Message& message, TimeSpan timeout) at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout) at System.ServiceModel.Security.SecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates) at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
顺便说一句,我已经看到很多帖子指出,如果不加上时间戳,那么安全字段就不会出现。这不是一种选择。我们正在与之通信的服务要求时间戳记。
解决方案
回答
有趣的是你应该问这个问题。大约一年前,我问微软该如何做。当时,无法使用.NET 3.0。不知道这在3.5世界中是否有所改变。但是,没有,没有物理方法可以为请求添加安全性并使响应为空。
在我以前的雇主中,我们使用了一个模型,该模型要求在请求上使用证书的WS-Security标头,但响应不安全。
我们可以使用ASMX Web服务和WSE来执行此操作,但不能使用WCF v3.0来执行此操作。
回答
我们很有可能无法独自摆脱配置。我必须与Axxis进行一些集成工作(最终是WSE3-WCF的祖先),我必须编写一些代码并将其粘贴到WSE3的管道中,以在将其传递给WSE3之前对Axxis的响应进行按摩。好消息是,将这些处理程序添加到管道中非常简单,并且一旦进入处理程序,我们就可以获取SoapMessage的实例,并且可以使用它执行任何操作(例如删除时间戳记)
回答
Microsoft现在为此功能提供了一个修补程序。
http://support.microsoft.com/kb/971493