2013-03-22 50 views
0

如何验证我的WCF消息是否已签名?我的安装程序运行正常,但需要能够检查服务器端的签名。这是如何完成的?我正在使用MsmqIntegrationBinding,并使用X509Certificate2对其进行签名。如何验证我的WCF消息是经过签名和加密的?

var binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.Transport) 
      { 
       SerializationFormat = MsmqMessageSerializationFormat.Binary, 
       Security = new MsmqIntegrationSecurity() 
       { 
        Mode = MsmqIntegrationSecurityMode.Transport, 
        Transport = new MsmqTransportSecurity() 
        { 
         MsmqAuthenticationMode = MsmqAuthenticationMode.Certificate, 
         MsmqProtectionLevel = System.Net.Security.ProtectionLevel.Sign 
        } 
       } 
      }; 

EndpointAddress address = new EndpointAddress("myaddress"); 
ChannelFactory<IMyMessage> channelFactory = new ChannelFactory<IMyMessage>(binding, address); 

channelFactory.Credentials.ClientCertificate.Certificate = my_x509certificate2; 
IMyMessage channel = channelFactory.CreateChannel(); 

//create message and send using the channel 

回答

0

批注或者与此您的服务或您的操作:

[OperationContract(ProtectionLevel = ProtectionLevel.EncryptAndSign)] 

这基本上会执行它在服务器端/操作也不会,除非消息被签名和加密调用。

如果你需要更多的参考,检查的ProtectionLevel MSDN上:

http://msdn.microsoft.com/en-us/library/aa347692.aspx

+0

嗯,可能是签字不工作。我现在收到一个错误:“请求消息必须被保护,这是合约操作所要求的...保护必须由绑定提供('MsmqIntegrationBinding','http://tempuri.org/')。 “ – Random 2013-03-22 20:01:16

+0

这就是这个注释的作用,它需要在调用操作之前在服务器端进行签名和加密。 – 2013-03-22 20:34:49

+0

因此,现在我必须确定为什么它没有按照我设置的方式发生。 – Random 2013-03-25 15:45:40

相关问题