I wrote a Windows application to test connectivity to SAP web services clients. An X509 certificate certificate is required to call the web service.
After reading various articles on the Internet, I came up with three ways to connect an X509 certificate to a web service call. Unfortunately, all of these attempts return 401 Unauthorized Access. However, I can connect to the web service through the URL in IE.
Does anyone have any opinions on what I can do wrong? I am using WSE 3.0, and the three methods that I use to attach the certificate are as follows: -
Certificate
X509Certificate2 oCert = GetSecurityCertificate(oCertificate); svc.ClientCertificates.Add(oCert);
Token
X509SecurityToken oToken = GetSecurityToken(oCertificate); svc.RequestSoapContext.Security.Tokens.Add(oToken);
Politics
SAPX509Assertion sapX509Assertion = new SAPX509Assertion(oCertificate, oStoreLocation, oStoreName, oFindType); svc.SetPolicy(sapX509Assertion.Policy());
GetSecurityToken () and GetSecuirtyCertificate search the certificate store. SAPX509Assertion does the following: -
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; }
Update Ok, now I have a WCF call. I could not use the BasicHttpBinding method shown by Eugarps as it complained that I was connecting to the https address and the expected http ... which made sense. The code that I have now is: -
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);
I still cannot connect to the SAP web service. The error I get is: "The HTTP request is unauthorized using the Negotiate client authentication scheme. I also tried using
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
which returned a similar error.
Does anyone have any additional suggestions or ideas on where I am going wrong?