我已经编写了一个Windows应用程序来测试与客户端SAP Web服务的连接。 Web服务调用需要X509证书安全性。从C#.NET应用程序连接到SAP Web服务
在阅读互联网上的各种文章后,我想出了三种方法将X509证书附加到Web服务调用中。不幸的是,所有这些尝试都会返回“401未授权访问”。但是,我可以通过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;
}
更新 OK,我现在有一个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;
其中返回了类似的错误。
有没有人有任何进一步的建议或想法,我哪里去错了?
'ZfhhrGbbapiZgeeamsCreateabsResponse' ...我的眼睛... – 2011-03-28 14:08:47
我知道!不是用户友好的命名约定。 – grimorde 2012-01-27 13:21:54