- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 SoapUI 工具中,我使用传出 WS-Security 配置签名为 BinarySecurityToken,算法为 CanonicalizationMethod 和 SignatureMethod 配置了 .Jks 文件,它运行良好。
现在我尝试从 C# 代码中使用,如下所示:
SprintApiService.QueryCsaPortTypeClient client = new QueryCsaPortTypeClient();
ClientCredentials ce = new ClientCredentials();
string fileName = Server.MapPath("");
fileName = fileName + "/test-01.pfx";
ce.ClientCertificate.Certificate = new X509Certificate2(fileName, "tag123");
var val = ce.ClientCertificate.Certificate.GetSerialNumber();
ce.ClientCertificate.SetCertificate("CN=jaitest-01, OU=TPA, OU=BMP, OU=Projects, O=Sprint, C=us", StoreLocation.CurrentUser, StoreName.TrustedPeople);
System.IdentityModel.Selectors.SecurityTokenManager sTokenMgr = ce.CreateSecurityTokenManager();
//var sTokenMgr = ce.CreateSecurityTokenManager();
但是我没能成功。我总是收到“被客户拒绝(政策)”的消息,请帮助我。
这是在 SoapUI 工具中创建的示例请求:
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp wsu:Id="Timestamp-c55ce328-af36-4b0f-97d8-3bab57ee6a46" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2014-02-18T12:27:52Z</wsu:Created>
<wsu:Expires>2014-02-18T12:32:52Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken wsu:Id="SecurityToken-1da2e6b0-3a0d-4943-bcae-de0805d9c4c5" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">MIIDmTCCAwKgAwIBAgIERxqCLDANBgkqhkiG9w0BAQUFADAeMQswCQYDVQQGEwJVUzEPMA0GA1UEChMGU3ByaW50MB4XDTExMDgwMjIwMDc0OVoXDTE4MDgwNDA0MDAwMFowYjELMAkGA1UEBhMCVVMxDzANBgNVBAoTBlNwcmludDERMA8GA1UECxMIUHJvamVjdHMxDDAKBgNVBAsTA0JNUDEMMAoGA1UECxMDVFBBMRMwEQYDVQQDEwpzcHJpbnQtbXNvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCG2yDWPQBNG9bjt+sVMzlaooX3jON7tOoqtIxPkXl7XCEvbzZpXL2tYtHXqxVfPo9h1weulbj0dE4LlVjlTjzW4upBI92StqDVYdzTLvZWie1fEslIThHDoX7paQpnrSew3TZ6fk4qVnF4h44J/rLnFt3jLEO6IyRhddganpoOowIDAQABo4IBnjCCAZowCwYDVR0PBAQDAgWgMCsGA1UdEAQkMCKADzIwMTEwODAyMjAwNzQ5WoEPMjAxODA4MDQwNDAwMDBaMBEGCWCGSAGG+EIBAQQEAwIFoDCB5AYDVR0fBIHcMIHZMDagNKAypDAwLjELMAkGA1UEBhMCVVMxDzANBgNVBAoTBlNwcmludDEOMAwGA1UEAxMFQ1JMMjkwgZ6ggZuggZiGSmxkYXA6Ly9jYXg1MDAxLnNwcmludC5jb206Mzg5L289U3ByaW50LGM9VVM/Y2VydGlmaWNhdGVSZXZvY2F0aW9uTGlzdD9iYXNlhkpsZGFwOi8vY2F4NTAwMi5zcHJpbnQuY29tOjM4OS9vPVNwcmludCxjPVVTP2NlcnRpZmljYXRlUmV2b2NhdGlvbkxpc3Q/YmFzZTAfBgNVHSMEGDAWgBRFTY2yujBdccYEb58W/Dt7VY3NHzAdBgNVHQ4EFgQUzUEoNuQ9ummaIU8K6h28izpV2YUwCQYDVR0TBAIwADAZBgkqhkiG9n0HQQAEDDAKGwRWNy4xAwIDKDANBgkqhkiG9w0BAQUFAAOBgQCTDjwpnYdx9JZpBrIwm4qIF4tZmXCCUIBEcoER1oUw/NSdgbbRjpU5AxUR/aK1K3taa27HS+WBQYTeMw+Y/LFhp8m+UjHBx/O1kfk4JAz201Kk0HeGgFvt9sscLfK8YD0aavdDJ6Z0rMpHBlcv8VQ7P+1zqJLay3TY+atl9wuD/Q==</wsse: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="#Timestamp-c55ce328-af36-4b0f-97d8-3bab57ee6a46">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>8H8usvOvRYPwOKHVHdOXO6Y3Cz4=</DigestValue>
</Reference>
<Reference URI="#Body-db900962-5b93-4a49-a70a-a1745bed8255">
<Transforms>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>54u/0PxaY+S7RigxrisF2Chnplc=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>HC10RHq8lweC1KLGAzw1pxjju5LbWASn5GUCxane36DqUxaXQQnBrF0fyBkpI70H+ncrYaO00sxVd1QWnLfYxzl/YEWfHus/qObmFckRnNsEnx9MV5ejHhntbXdzIc9RFbXoFGPcoEGAsKoUbeOi7UWKbofzATG6VMlKhLFz01k=</SignatureValue>
<KeyInfo>
<wsse:SecurityTokenReference xmlns="">
<wsse:Reference URI="#SecurityToken-1da2e6b0-3a0d-4943-bcae-de0805d9c4c5" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
</wsse:Security>
谢谢...
最佳答案
Thank god, finally i've found a solution after a long research, googling/binging and hard work. Just Recap: Third party web service (coded in Java) with X509 SecurityToken Https certificate consume in .NET.
Yes, we can consume the above service using old technology using WSE 2.0 / WSE 3.0 (Web Services Enhancements) and Latest using WCF. I've just tried using WSE 2.0 it's working as expected but with Error code "WSE464: No policy could be found for this message" still i can able to get see response in try..catch block and use appropriate decrypt XML response message.
遵循的步骤
安装客户端给定的证书(.pfx)
在运行命令中打开 Microsoft 管理控制台 (MMC),输入 mmc → EnterA。文件 → 添加/删除管理单元 → 在列表框中选择证书 → 单击添加 → 选择我的
当前用户 → 完成 –> 单击“确定”。
b. Select Trusted Root Certification → Expand it → Select Certificate → Right click on
Certificate → Select All Tasks → Import → Select your Certificate location and finish the
wizard process
对本地计算机(本地计算机)重复步骤 2
安装 Microsoft WSE(Web 服务增强功能)2.0 SP3/WSE 3.0 注意。 WSE 2.0/3.0 将仅支持 .Net Framework 2.0。 http://www.microsoft.com/en-in/download/details.aspx?id=23689
在 Visual Studio 中创建新的 Web 应用程序项目展开项目 → 右键单击引用 → 添加服务引用 → 高级 → 添加 Web 引用 → 将您的服务 WSDL 链接粘贴到 URL 文本框中 → 单击“Go”按钮(指向右箭头)→ 由于它是 https,因此将显示带有警告消息的弹出窗口,单击是,直到停止 → 输入 Web 引用名称并单击“添加引用”按钮右键单击→引用→添加引用→单击浏览→\Program Files\Microsoft WSE\v2.0\→选择“Microsoft.Web.Services2.dll”→单击添加立即生成代理/ stub 类 → 在 Web Reference 文件夹下查找 Reference.cs 文件(如果不可见),单击“解决方案资源管理器中的显示所有文件”。 → 打开 Reference.cs 文件并将“System.Web.Services.Protocols.SoapHttpClientProtocol”替换为“WebServicesClientProtocol”
protected void Page_Load(object sender, EventArgs e)
{
private static string ClientBase64KeyId = "XPaTfx6Lx8dV/oh6ebOeOo4Xdummy";
MyService myClient = new MyService();
try
{
SecurityToken signingToken = GetClientToken(false);
//Get the SoapContext for the SOAP request.
SoapContext requestContext = client.RequestSoapContext;
// Expire this message one minute after it is sent.
requestContext.Security.Timestamp.TtlInSeconds = 3600;
// Add the X509 certificate to the WS-Security header.
requestContext.Security.Tokens.Add(signingToken);
MessageSignature sig = new MessageSignature(signingToken);
requestContext.Security.Elements.Add(sig);
RequestClass request = new RequestClass();
request.Name =””;
ResponceClass responce = myClient.QueryCsa(request);
}
catch(Exception ex)
{
lblResultMessage.Text = ex.Message;
}
public static X509SecurityToken GetClientToken(bool selectFromList)
{
X509SecurityToken token = null;
// Open the CurrentUser Certificate Store and try MyStore only
X509CertificateStore store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore);
if (selectFromList)
{
//token = RetrieveTokenFromDialog(store);
}
else
{
token = RetrieveTokenFromStore(store, ClientBase64KeyId);
}
return token;
}
private static X509SecurityToken RetrieveTokenFromStore(X509CertificateStore store, string keyIdentifier)
{
if (store == null)
throw new ArgumentNullException("store");
X509SecurityToken token = null;
try
{
if (store.OpenRead())
{
// Place the key ID of the certificate in a byte array
// This KeyID represents the Wse2Quickstart certificate included with the WSE 2.0 Quickstarts
// ClientBase64KeyId is defined in the ClientBase.AppBase class
Microsoft.Web.Services2.Security.X509.X509CertificateCollection certs = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(keyIdentifier));
if (certs.Count > 0)
{
if (!certs[0].SupportsDigitalSignature ||
(certs[0].Key == null))
{
//MessageBox.Show(
// "The certificate must support digital " +
// "signatures and have a private key available.");
//securityToken = null;
}
// Get the first certificate in the collection
token = new X509SecurityToken(((Microsoft.Web.Services2.Security.X509.X509Certificate)certs[0]));
}
}
}
finally
{
if (store != null)
store.Close();
}
return token;
}
}
在您的页面中添加以下代码,并从 X509 证书工具获取 ClientBase64KeyId 值。
开始 → 程序文件 → Microsoft WSE 2.0 → X509 证书工具 → 选择证书位置为本地计算机 → 名称为个人 → 单击打开证书按钮,列出证书并选择使用 MMC 安装的相应证书。现在从 key 标识符(Base64 编码)值中选择值并在下面的代码中使用它。如果您的应用程序是 Asp.Net Web 应用程序,则可能无法访问它,因此请单击“查看私钥文件属性”按钮并在同一工具本身中分配适当的安全权限。
我们几乎完成了 70% 的工作。现在要做的非常关键的部分...是的,我们将应用策略详细信息。这都是与 X509 证书相关的安全策略,它定义了将要签名的部分(签名)、加密、完整性、 secret 性等等。不要 panic ,我们有名为 WSE 2.0 工具的助手,是的,chumma :) 尝试一下开始 → 程序文件 → Microsoft WSE 2.0 → 配置编辑器 → 文件 → 打开 → 从应用程序指向 Web.config
常规 => 选中两个复选框
安全、路由和自定义过滤器 => 他们不叫我:)所以离开它吧。
政策 => 非常重要。 1.勾选启用策略 2.点击添加 → 名称
/输入任意名称 → 下一步 → 保留默认值(安全客户端
应用程序)→(默认)下一步→下一步→(默认:X509证书)→下一步 → 选择证书 → 从
中选择适当的证书列表 → 确定 → 下一步 → 完成
TokenIssuing => 保留
诊断=>选中适当的复选框以进行跟踪和
记录目的
文件→保存→关闭:)
现在我们已经创建了在 Web.config 文件中引用的policyCache.config。这里我们在 中添加了我们的 HTTPS 服务 URL。完成
这是通过 WSE 2.0 实现的。是的,我知道这是旧技术。我是尝试使用 WCF 作为客户端进行消费...我将在下一次 session 中发布...
:) 快乐编程:)贾桑卡
关于web-services - 如何在c#中使用第三方https wsdl web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21861230/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!