gri*_*rde 7 .net c# sap c#-3.0
我编写了一个Windows应用程序来测试与客户端SAP Web服务的连接.Web服务调用需要X509证书安全性.
在互联网上阅读各种文章之后,我想出了三种方法将X509证书附加到Web服务调用上.不幸的是,所有这些尝试都返回'401 Unauthorized Access'.但是,我可以通过IE中的URL连接到Web服务.
有没有人对我可能做错了什么?我使用的是WSE 3.0,我用来附加证书的三种方法如下: -
证书
X509Certificate2 oCert = GetSecurityCertificate(oCertificate);
svc.ClientCertificates.Add(oCert);
Run Code Online (Sandbox Code Playgroud)
代币
X509SecurityToken oToken = GetSecurityToken(oCertificate);
svc.RequestSoapContext.Security.Tokens.Add(oToken);
Run Code Online (Sandbox Code Playgroud)
政策
SAPX509Assertion sapX509Assertion = new SAPX509Assertion(oCertificate, oStoreLocation, oStoreName, oFindType);
svc.SetPolicy(sapX509Assertion.Policy());
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
更新 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);
Run Code Online (Sandbox Code Playgroud)
它仍然无法连接到SAP Web服务.我收到的错误是"HTTP请求未经授权,客户端身份验证方案'协商'".我也试过用
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
Run Code Online (Sandbox Code Playgroud)
它返回了类似的错误.
有没有人对我出错的地方有任何进一步的建议或想法?
gri*_*rde -1
经过这么长时间,客户终于找到了 SAP 端的人来处理这个问题。事实证明,我们提供的 WSDL 文件不正确,并且认证也有误。我使用新的 WSDL 文件重新运行我的代码,它第一次就工作了。
| 归档时间: |
|
| 查看次数: |
21749 次 |
| 最近记录: |