【发布时间】:2014-08-28 20:15:15
【问题描述】:
我正在尝试使用用户名令牌(用户名/密码)和客户端证书来调用 Web 服务(不确定后端是用什么编写的)。
短版:如果我有客户端证书和用户名/密码可以使用,需要哪种 WCF 代码/配置组合来生成下面的 SOAP 标头?
加长版
以下是 Visual Studio 2010 中“添加服务引用”生成的服务接口(更改名称/URI 以保护无辜者):
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://servicenamespacehere", ConfigurationName="Service.Contract.ConfigName.Here")]
public interface IBackendService {
// CODEGEN: ...
[System.ServiceModel.OperationContractAttribute(IsOneWay=true, Action="http://servicenamespacehere#Method1")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
void Method1(Method1Params request);
我需要生成的调用的 SOAP 安全标头如下所示:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2014-08-26T20:22:50.522Z</u:Created>
<u:Expires>2014-08-26T20:27:50.522Z</u:Expires>
</u:Timestamp>
<o:UsernameToken u:Id="uuid-6f243c9c-fd85-4634-8b57-cb196aee3195-60591">
<o:Username>myUser</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">somePwd</o:Password>
</o:UsernameToken>
<o:BinarySecurityToken u:Id="uuid-6f243c9c-fd85-4634-8b57-cb196aee3195-60592" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">BASE64TOKENHERE=</o:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#_0">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>BASE64DIGESTHERE=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>BASE64SIGNATUREHERE=</SignatureValue>
<KeyInfo>
<o:SecurityTokenReference>
<o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-6f243c9c-fd85-4634-8b57-cb196aee3195-60592"/>
</o:SecurityTokenReference>
</KeyInfo>
</Signature>
</o:Security>
</s:Header>
SOAP XML PAYLOAD FOLLOWS...
我找不到任何支持客户端消息凭据的 WCF 绑定/端点设置组合,其中包括 UserName 和 Certificate 类型。
作为一些搜索的结果,我发现有人表示我需要自定义 WCF 绑定来包含这两种凭据类型,他们指向此 MSDN 链接:
http://msdn.microsoft.com/en-us/library/ms751480(v=vs.100).aspx
但是当我按照代码示例时,我得到一个错误:
'The service certificate is not provided for target'
现在 ClientCredentials 对象同时具有 ClientCertificate 属性(我通过客户端证书的指纹成功加载了该属性),但 ServiceCertificate 的用途是什么?
如果我只有一个客户端证书和一个用户名/密码可以使用,那么生成上面的 SOAP 标头需要什么 WCF 代码/配置组合?
【问题讨论】:
标签: c# .net wcf soap ws-security