我还有其他问题。如何对消息正文进行编码?
在客户端,我使用此代码
NetTcpBinding binding = new NetTcpBinding { Security = { Mode = SecurityMode.Message } };
binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
//_foreignServiceCertificate - is the B certificate
//_foreignServiceUrl - is the url of the B service
var endpointIdentity = EndpointIdentity.CreateDnsIdentity(_foreignServiceCertificate.SubjectName.GetCommonName());
var endPointAddress = new EndpointAddress(new Uri(_foreignServiceUrl), endpointIdentity);
//_thisPeerCertificate - is the A certificate
var channelFactory = new ChannelFactory<IChatService>(binding, endPointAddress);
channelFactory.Credentials.ClientCertificate.Certificate = _thisPeerCertificate;
channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;
channelFactory.Credentials.ServiceCertificate.Authentication.CustomCertificateValidator = new ClientCertificateValidation(_foreignServiceCertificate);
IChatService serviceProxy = channelFactory.CreateChannel();
var chatMessage = new ChatMessage { Message = message, MessageSender = _thisPeerCertificate };
serviceProxy.SendMessage(chatMessage);
您建议使用C公钥加密消息正文。并且消息正文将由 wcf 基础设施使用B公钥额外加密。我做对了吗?
是否正确,我可以使用 IEndPointBehavior 的自定义实现和 IClientMessageInspector 的自定义实现(方法 beforesendrequest)对消息体进行编码?