Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   C++ SOAP web service | WS-Security authentication (https://www.delphipraxis.net/193706-soap-web-service-%7C-ws-security-authentication.html)

ThomasMü 31. Aug 2017 07:35


SOAP web service | WS-Security authentication
 
Hallo,

ich versuche einen Client zu erstellen, der einen SOAP Webservice verwendet.
Dazu verwende ich den Embarcadero C++Builder 10 Seattle.
Wenn ich eine Anfrage an den Webservice sende, erhälte ich folgende Fehlermeldung:
Zitat:

An error occurred when verifying security for the message
Die Anfrage sieht folgendermaßen aus:
Delphi-Quellcode:
POST https://**** HTTP/1.1 
SOAPAction: "****"
Content-Type: text/xml; charset=utf-8
User-Agent: CodeGear SOAP 1.3
Host: ****
Content-Length: 349
Connection: Keep-Alive
Cache-Control: no-cache

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body><****><****>****</****></****></SOAP-ENV:Body></SOAP-ENV:Envelope>
In SoapUI konnte ich eine erfolgreiche Anfrage senden indem ich bei "username" und "password" den Benutzernamen und das Password, sowie bei "WSS-Password Type" "PasswordText" ausgewählt habe.

Die Anfrage von SoapUI sah folgendermaßen aus:
Delphi-Quellcode:
POST https://**** HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://****"
Content-Length: 1069
Host: ****
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header><wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-****"><wsse:Username>****</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">****</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">****</wsse:Nonce><wsu:Created>2017-08-30T12:48:09.048Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>
   <soapenv:Body>
      <tem:****>
         <!--Optional:-->
         <tem:****>****</tem:****>
      </tem:****>
   </soapenv:Body>
</soapenv:Envelope>
Wie kann ich den header der Anfrage in meiner Anwendung hinzufügen?
Ich habe bisher nur Beispiele gefunden, wie die basic authentification im http header hinzugefügt wird.

Viele Grüße
Thomas

Papaschlumpf73 31. Aug 2017 08:43

AW: SOAP web service | WS-Security authentication
 
In Delphi mache ich das mit der Komponente HTTPRIO - müsste ja in C++ fast genauso sein. In dem Ereignis BeforeExecute kann man den ganzen Stream so basteln, wie man Lust hat... Ist nicht besonders elegant; funktioniert aber.

Delphi-Quellcode:
procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: string; SOAPRequest: TStream);
begin
with TStringList.Create do
 try
 SOAPRequest.Position:=0; LoadFromStream(SOAPRequest, TEncoding.UTF8);
 Text:=StringReplace(Text, '<SOAP-ENV:Body>', '<SOAP-ENV:Header>und mein ganzer Header-Kram kommt hier rein'+'</SOAP-ENV:Header><SOAP-ENV:Body>', [rfReplaceAll]);
 SOAPRequest.Position:=0; SOAPRequest.Size:=0;
 SaveToStream(SOAPRequest, TEncoding.UTF8);
 finally Free; end;
end;

ThomasMü 31. Aug 2017 11:04

AW: SOAP web service | WS-Security authentication
 
Zitat:

Zitat von Papaschlumpf73 (Beitrag 1380019)
In Delphi mache ich das mit der Komponente HTTPRIO - müsste ja in C++ fast genauso sein. In dem Ereignis BeforeExecute kann man den ganzen Stream so basteln, wie man Lust hat... Ist nicht besonders elegant; funktioniert aber.

Delphi-Quellcode:
procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: string; SOAPRequest: TStream);
begin
with TStringList.Create do
 try
 SOAPRequest.Position:=0; LoadFromStream(SOAPRequest, TEncoding.UTF8);
 Text:=StringReplace(Text, '<SOAP-ENV:Body>', '<SOAP-ENV:Header>und mein ganzer Header-Kram kommt hier rein'+'</SOAP-ENV:Header><SOAP-ENV:Body>', [rfReplaceAll]);
 SOAPRequest.Position:=0; SOAPRequest.Size:=0;
 SaveToStream(SOAPRequest, TEncoding.UTF8);
 finally Free; end;
end;

Vielen Dank für deine Hilfe.
Ich konnte den Request damit entsprechend anpassen, dass es funktioniert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:53 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz