【发布时间】:2019-10-28 17:37:29
【问题描述】:
我正在尝试在 Visual Studio 2019 中构建一个客户端,该客户端将使用一个使用 id/pass 和证书保护的 SOAP 服务。
我通过导入 WSDL 创建了一个 SoapUI 项目,然后将项目上的 ws-security 设置配置为具有传出签名并导入具有我要使用的证书的密钥库。最后,我在使用 Basic 的请求上设置了身份验证,设置了 id/pass 并在 Outgoing WSS 下拉菜单中选择了我的传出签名。完成所有这些后,我可以使用 Soap UI 完美地调用该服务。
在 Visual Studio 中,我创建了一个新的控制台项目,使用相同的 WSDL 添加了一个连接的服务引用,现在我正在尝试编写代码。我尝试通过这样做来设置凭据
System.ServiceModel.BasicHttpsBinding myBinding = new System.ServiceModel.BasicHttpsBinding();
System.ServiceModel.EndpointAddress myAddress = new System.ServiceModel.EndpointAddress("url");
ServiceReference1.CaseTypeClient myClient = new ServiceReference1.CaseTypeClient(myBinding, myAddress);
myClient.ClientCredentials.UserName.UserName = "ID";
myClient.ClientCredentials.UserName.Password = "Pass";
System.Security.Cryptography.X509Certificates.X509Certificate2 myCert = new System.Security.Cryptography.X509Certificates.X509Certificate2("CertFileName", "CertPass");
myClient.ClientCredentials.ClientCertificate.Certificate = myCert;
但是,当我调用该方法时,我从服务中返回了一个 soapfault,说“XmlException: Unbound prefix used inqualified name 'wsse:FailedAuthentication'”。
什么是做我想要完成的事情的正确方法?
【问题讨论】:
标签: c# .net wcf ws-security wsse