考虑一个WCF服务,其中的目的是使在传输层所需的客户端证书(客户端证书设置为“必需的”,在IIS)。 以及,将有在消息层的用户名验证。
现在,我已经看到了这个问题已经:
WCF客户端证书和用户名凭据禁止
我能有所了解发生了什么事情在那里,并认识到固有的WCF不允许两者。 我同样的步骤赴代码按上面的链接海报,发现同样的结果...消息级用户名凭据传递(在SOAP头在我的情况),但客户端证书(尽管是当请求的客户端在VS调试观察)没有实际被由端点处理附接。
所以现在谈到有我困惑的部分。 我决定一定程度上破解它。 我不知道为什么这个作品完全一样,我想......它会过去的IIS客户端证书的要求,用户名被传递给WCF服务和所有只是工作。 然而,WCF不允许我这样做只是使用WCF配置文件或代码(即我能找到)。 为什么?
// sets up a proxy client based on endpoint config
// basically just here to get the URL.
this.InitializeSubmitClient();
// these get used to create the HttpWebRequest
string url = this.submitClient.Endpoint.Address.ToString();
string action = "SubmitCDA";
// this deserializes an XML file which is the "shell" of SOAP document and inject username/password into SOAP Security node
XmlDocument soapEnvelopeXml = XMLHelper.CreateSoapDocument(this.txtSubmitCdaXmlFile.Text, this.txtAdAccount.Text, this.txtPassword.Text);
HttpWebRequest webRequest = XMLHelper.CreateWebRequest(url, action);
// saves the SOAP XML into the webRequest stream.
XMLHelper.InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
// attach the cert
if (this.chkSendClientCert.Checked)
{
X509Certificate myCert = X509Certificate.CreateFromCertFile(@"C:\temp\CDX-IHAT_DevClientCert.cer");
webRequest.ClientCertificates.Add(myCert);
}
else
{
webRequest.ClientCertificates.Clear();
}
// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
更为复杂的是,WCF服务,这适用于一个BizTalk服务。