我正在尝试使用带有证书的WCF来调用Web服务来签署消息。
服务器仅支持以下规范化算法:“http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments”
默认情况下,WCF使用“http://www.w3.org/2001/10/xml-exc-c14n#”
由于我无法使用配置文件对其进行配置,因此我创建了一个自定义绑定,其中我设置了自定义SecurityAlgorithmSuite以强制WCF使用服务所期望的规范化算法。 这是我的自定义绑定:
public class TestBinding : Binding
{
public override BindingElementCollection CreateBindingElements()
{
var sec = TransportSecurityBindingElement.CreateCertificateOverTransportBindingElement();
sec.MessageSecurityVersion = MessageSecurityVersion
.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
sec.EnableUnsecuredResponse = true;
sec.DefaultAlgorithmSuite = new TestSecurityAlgorithmSuite();
return new BindingElementCollection(new BindingElement[] {
new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap11WSAddressing10 },
sec,
new HttpsTransportBindingElement() { RequireClientCertificate = true }
});
}
public override string Scheme
{
get { return new HttpsTransportBindingElement().Scheme; }
}
}
算法套件:
public class TestSecurityAlgorithmSuite : Basic256SecurityAlgorithmSuite
{
public override string DefaultCanonicalizationAlgorithm
{
get { return "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"; }
}
public override string ToString()
{
return "TestSecurityAlgorithmSuite";
}
}
不幸的是,我收到错误:
Canonicalization algorithm 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' is not supported.
Server stack trace:
à System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.StartPrimarySignatureCore(SecurityToken token, SecurityKeyIdentifier keyIdentifier, MessagePartSpecification signatureParts, Boolean generateTargettableSignature)
à System.ServiceModel.Security.WSSecurityOneDotZeroSendSecurityHeader.CreateSupportingSignature(SecurityToken token, SecurityKeyIdentifier identifier)
à System.ServiceModel.Security.SendSecurityHeader.SignWithSupportingToken(SecurityToken token, SecurityKeyIdentifierClause identifierClause)
à System.ServiceModel.Security.SendSecurityHeader.SignWithSupportingTokens()
à System.ServiceModel.Security.SendSecurityHeader.CompleteSecurityApplication()
à System.ServiceModel.Security.SecurityAppliedMessage.OnWriteMessage(XmlDictionaryWriter writer)
à System.ServiceModel.Channels.Message.WriteMessage(XmlDictionaryWriter writer)
à System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
à System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
à System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)
à System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message, Boolean shouldRecycleBuffer)
à System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
à System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
à System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
à System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
à System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
à System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
à System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
à System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
à System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)'
我开始认为所有希望都失去了。有没有办法让WCF使用所需的算法?
答案 0 :(得分:0)
不幸的是,例外情况是自我描述性的:当前版本的WCF不支持“http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments”规范化算法。