我编写了一个 Windows 应用程序来测试与客户端 SAP Web 服务的连接。Web 服务调用需要 X509 证书安全性。
在阅读了互联网上的各种文章后,我想出了三种将 X509 证书附加到 Web 服务调用的方法。不幸的是,所有这些尝试都返回“401 Unauthorized Access”。但是,我可以通过 IE 中的 URL 连接到 Web 服务。
有人对我可能做错了什么有任何建议吗?我正在使用 WSE 3.0,我用来附加证书的三种方法如下:-
证书
X509Certificate2 oCert = GetSecurityCertificate(oCertificate);
svc.ClientCertificates.Add(oCert);
令牌
X509SecurityToken oToken = GetSecurityToken(oCertificate);
svc.RequestSoapContext.Security.Tokens.Add(oToken);
政策
SAPX509Assertion sapX509Assertion = new SAPX509Assertion(oCertificate, oStoreLocation, oStoreName, oFindType);
svc.SetPolicy(sapX509Assertion.Policy());
GetSecurityToken() 和 GetSecuirtyCertificate 都搜索证书存储区。SAPX509Assertion 这样做:-
public SAPX509Assertion(String certSubject, StoreLocation oStoreLocation, StoreName oStoreName, X509FindType oFindType)
{
ClientX509TokenProvider = new X509TokenProvider(oStoreLocation,
oStoreName, certSubject, oFindType);
ServiceX509TokenProvider = new X509TokenProvider(oStoreLocation,
oStoreName, certSubject, oFindType);
Protection.Request.EncryptBody = false;
Protection.Response.EncryptBody = false;
}
更新 好的,我现在有一个 WCF 调用。我无法使用 Eugarps 显示的 BasicHttpBinding 方法,因为它抱怨我正在连接到 https 地址并期望 http...这是有道理的。我现在拥有的代码是:-
var binding = new WSHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Security.Mode = SecurityMode.Transport;
WCFConnection.CreateAbsenceWSlow.ZWSDHTM_GB_AMS_CREATEABS_lowClient client;
CreateAbsenceWSlow.ZfhhrGbbapiZgeeamsCreateabsResponse response;
CreateAbsenceWSlow.ZfhhrGbbapiZgeeamsCreateabs data;
//Assign address
var address = new EndpointAddress(sUrl);
//Create service client
client = new CreateAbsenceWSlow.ZWSDHTM_GB_AMS_CREATEABS_lowClient(binding, address);
//Assign credentials
client.ClientCredentials.UserName.UserName = sUserName;
client.ClientCredentials.UserName.Password = sPassword;
response = new CreateAbsenceWSlow.ZfhhrGbbapiZgeeamsCreateabsResponse();
data = new WCFConnection.CreateAbsenceWSlow.ZfhhrGbbapiZgeeamsCreateabs();
response = client.ZfhhrGbbapiZgeeamsCreateabs(data);
它仍然无法连接到 SAP Web 服务。我收到的错误是“HTTP 请求未经客户端身份验证方案‘协商’授权”。我也尝试过使用
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
它返回了类似的错误。
有人对我哪里出错有任何进一步的建议或想法吗?