2010-09-08 90 views
7

我已经编写了一个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; 

其中返回了类似的错误。

有没有人有任何进一步的建议或想法,我哪里去错了?

+0

'ZfhhrGbbapiZgeeamsCreateabsResponse' ...我的眼睛... – 2011-03-28 14:08:47

+0

我知道!不是用户友好的命名约定。 – grimorde 2012-01-27 13:21:54

回答

-1

经过这段时间,客户终于找到了一个人来处理SAP的问题。发现我们提供的WSDL文件不正确,认证错误。我用新的WSDL文件重新编写了代码,并且它第一次运行。

+0

这不是一个答案。你需要删除你的问题,因为它不会帮助任何人。 – ataravati 2016-11-22 19:37:54

-2

您的证书是否恰好映射到用户存储中的有效用户?

+0

证书是由SAP结尾处的人员生成的,但是如果IE正在拾取并成功使用证书,则必须将答案视为是。 – grimorde 2010-09-09 09:18:04

+0

请在评论中提问,不要在回答中发帖提问。 – Restuta 2010-09-12 19:18:02

4

现在,这一切都来自我自己的经验,所以其中一些可能是错误的,但这里是我的理解过程(我没有收到任何文档,我的公司在开始实施之前没有调用SAP的经验)。

SAP WS调用仅支持WCF BasicHttpBinding,并且据我所知只能使用纯文本凭据。这意味着如果您需要使通信保密(Intranet外部,或Intranet内的敏感数据),您将需要使用IPSec或HTTPS。我们的SAP服务器没有配置HTTPS,但我们使用VPN与IPSec进行外部通信。需要注意的是,默认情况下,SAP GUI也不会使通信保密。在这种情况下,通过使用下面详细介绍的方法,您比使用GUI 7.1查找敏感数据的商业用户更加安全。下面是如何连接到我们的SAP内部服务器:

 //Create binding 
     //Note, this is not secure but it's not up to us to decide. This should only ever be run within 
     //the VPN or Intranet where IPSec is active. If SAP is ever directly from outside the network, 
     //credentials and messages will not be private. 
     var binding = new BasicHttpBinding(); 
     binding.MaxReceivedMessageSize = int.MaxValue; 
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
     binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 

     //Assign address 
     var address = new EndpointAddress(Host); 

     //Create service client 
     var client = new SAP_RFC_READ_TABLE.RFC_READ_TABLEPortTypeClient(binding, address); 

     //Assign credentials 
     client.ClientCredentials.UserName.UserName = User; 
     client.ClientCredentials.UserName.Password = Password; 

据我已经能够确定,不支持的消息级别的安全性,并绑定除了basicHttpBinding的(SOAP 1.1)不被支持。

正如我所说的,这是所有的经验,而不是从培训,所以如果任何人可以通过评论添加的东西,请这样做。

+0

此外,我发布的示例使用动态创建的绑定,这将禁用ChannelFactory缓存。如果有人在制作中使用此示例,请记住这一点。 – Sprague 2010-09-15 15:48:57

+0

我正在使用WSE3.0过程,但会考虑使用WCF和上面的示例进行重写。 – grimorde 2010-10-07 07:16:33

2

我面临同样的问题,似乎我已经在这里找到了溶剂:http://ddkonline.blogspot.com/2009/08/calling-sap-pi-web-service-using-wcf.html

 CustomBinding binding = new CustomBinding(); 
     binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8)); 
     HttpsTransportBindingElement transport = new HttpsTransportBindingElement(); 
     transport.AuthenticationScheme = AuthenticationSchemes.Basic; 
     //transport.ProxyAuthenticationScheme = AuthenticationSchemes.Basic; 
     transport.Realm = "XISOAPApps"; 
     binding.Elements.Add(transport); 
     var address = new EndpointAddress("https://foooo"); 
     ........ create client proxy class 


     service.ClientCredentials.UserName.UserName = "<login>"; 
     service.ClientCredentials.UserName.Password = "<password>"; 

可惜的是我不能在我的应用程序中使用WCF,我一定要坚持使用.NET 2.0和WSE 3.0,和我wounder如果有人能找到sollution到?

相关问题