Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Webservice Java nach Delphi (https://www.delphipraxis.net/183051-webservice-java-nach-delphi.html)

meierg 8. Dez 2014 08:21


Webservice Java nach Delphi
 
Hallo ...

ich möchte einen WS Service nutzen und habe von dort die unten stehenden java Zeilen bekommen.
Es ist mir zum Beispiel nicht klar, welche properties der IdHTTP ich setzen muss bzw. welche Methoden HTTP Methoden ich einsetzen soll. (IdHHTP.post oder get usw.) :pale:

Leider fehlt mir der Durchblick die SOAP request in Delphi 2010/Indy 10.1.5../IdHTTP umzusetzen.

Kann mir jemand einen Tipp geben - oder besser mehrere?

Danke!!!!



Delphi-Quellcode:
/**
       * logs the user in and gets the token
       * @param loginId
       * @param password
       * @return
       */


       private String login(String loginId, String password) {
              try {
            String httpsURL = "https://kon.saneke.....com:443/services/LandingPagesWS";
           
            URL myurl = new URL(httpsURL);
            HttpsURLConnection connection = (HttpsURLConnection)myurl.openConnection();
           
            String userpass = loginId + ":" + password;
            String encodedAuthorization = Base64.encode(userpass.getBytes()).toString();
            connection.setRequestProperty("authorization", "Basic " + encodedAuthorization);
           
            ResourceBundle bundle = ResourceBundle.getBundle("soapMessageTemplate");
            String soapTemplate = bundle.getString("landingpagesws.login");
           
            connection.setAllowUserInteraction(true);
            connection.setRequestProperty("POST", "https://kon.saneke.....com:443/services/LandingPagesWS HTTP/1.1");
            connection.setRequestProperty("Host", "kon.saneke....com:443");
            connection.setRequestProperty("Content-Length", Integer.toString(soapTemplate.length()) );
            connection.setRequestProperty("Content-Type","text/xml;charset=UTF-8");
            connection.setRequestProperty("SOAPAction", "");
            connection.setRequestProperty("Connection", "Keep-Alive");
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.connect();
           
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
            out.write(soapTemplate);
            out.flush();
            out.close();
           
            connection.getResponseCode();
           
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String outputString;
            StringBuffer sb = new StringBuffer();
            while ((outputString = in.readLine()) != null) {
                System.out.println(outputString);
                sb.append(outputString);
            }
            in.close();
            connection.disconnect();
            String returnString = sb.toString();
           
            int start = returnString.indexOf("<return>");
            int end = returnString.indexOf("</return>");
            String responseJSON = "";
             
            if ( start > 0 && end > 0 && end > start ) {
              responseJSON = returnString.substring(start, end);
            }
           
            try {
                // Convert the input which is in XML format to a JSON object.
              WebServiceResponse respJSON = new ObjectMapper().readValue(responseJSON, WebServiceResponse.class);
              String token = respJSON.getToken();
              if ( token != null && token != "" ) {
                     return respJSON.getToken();
              } else {
                     return "ERROR";
              }
            } catch (Exception e) {
                e.printStackTrace();
            }
              } catch (Exception e) {
                     e.printStackTrace();
              }
              return "ERROR";

mquadrat 8. Dez 2014 08:41

AW: Webservice Java nach Delphi
 
Am Besten übernimmst du den Code überhaupt nicht. Dort wird die SOAP Nachricht von Hand zusammen gebaut, anstatt automatisch generierte Proxy-Klassen zu verwenden. Das habe ich bisher eigentlich nur bei Web-Entwicklern gesehen. JSON als Rückgabe von einem SOAP Dienst schaut auch seltsam aus. Aber gut, für den Dienst kannst du ja nichts.

Ich persönlich würde mir von dem Dienst das WSDL File geben lassen und darauf aufbauend von Delphi die Proxy-Klassen erzeugen lassen. Dann hast du mit Encoding, Verschachtelung und dem ganzen Rest nämlich nichts zu tun und bist fein raus.


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:30 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