クライアントのSAPWebサービスへの接続をテストするためのWindowsアプリケーションを作成しました。Webサービス呼び出しには、X509証明書のセキュリティが必要です。
インターネット上のさまざまな記事を読んだ後、X509証明書をWebサービス呼び出しに添付する3つの方法を思いつきました。残念ながら、これらの試みはすべて「401UnauthorizedAccess」を返します。ただし、IEのURLを介してWebサービスに接続できます。
誰かが私が間違っているかもしれないことについて何か推測がありますか?私はWSE3.0を使用しており、証明書を添付するために使用している3つの方法は次のとおりです。
証明書
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呼び出しがあります。私はhttpsアドレスに接続していてhttpを期待していると文句を言ったのでEugarpsによって示されたBasicHttpBindingメソッドを使用できませんでした...それは理にかなっています。私が今持っているコードは次のとおりです:-
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);
それでもSAPWebサービスへの接続に失敗しています。私が受け取っているエラーは、「HTTPリクエストはクライアント認証スキーム「ネゴシエート」で許可されていません」です。私も使ってみました
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
同様のエラーが返されました。
誰かが私がどこで間違っているのかについてさらに提案やアイデアがありますか?