Dokumentation der SOAP Schnittstelle

Im folgenden Abschnitt wird ausführlich erklärt, wie man eine WSDL-Datei einliest und eine Verbindung zum Webservice aufbaut.

Programmiersprache Java mit Eclipse Mars for Java EE Developers

Folgen Sie der bebilderten Anleitung weiter unten und erstellen Sie sich so ein neues Webservice-Client Projekt mit Eclipse.
Erstellen Sie zwei neue Klassen im Package de.otela.soap.client:

ApiKey.java und SampleClient.java

Kopieren Sie sich die Codefragmente unterhalb der bebilderten Anleitung weiter unten in die neu erstellten Klassen.
Führen Sie das Projekt aus. Es erscheint eine Fehlermeldung, dass Ihnen noch keine gültigen Credentials zur Verfügung stehen.


Automatisch erstellte Klassen

generierter Code

  1. Erstellen Sie ein neues Webservice Client Projekt

    Erstellen eines Projekts

  2. Fügen Sie die URL der WSDL-Datei der otela Enterprise Systems ein:

    WSDL-Datei einfügen


  1. Erstellen Sie eine neue Klasse ApiKey.java im Client Package ohne Main-Methode

    Erstellung Client Class

    Listing ApiKey.java

    /**
     * Api-Key for otela Enterprise Systems
     *
     * The MIT License (MIT)
     *
     * @copyright Copyright(C) 2016 otela Enterprise Systems
     * @author    Markus Bröker<markus.broeker@otela.net>
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */
    package de.otela.soap.client;
    
    import java.io.FileInputStream;
    import java.util.Properties;
    
    public class ApiKey {
    
        private String login;
        private String password;
    
        private String serviceLogin;
        private String servicePassword;
    
        public ApiKey() {
            Properties properties = this.getProperties();
    
            if (properties == null) {
                throw new RuntimeException("Sie benötigen eine gültige credentials.ini Datei\n\n");
            }
    
            this.login = properties.getProperty("login");
            this.password = properties.getProperty("password");
    
            this.serviceLogin = properties.getProperty("servicelogin");
            this.servicePassword = properties.getProperty("servicepassword");
        }
    
        /**
         *
         * @return
         */
        private Properties getProperties() {
            try {
                Properties credentials = new Properties();
                FileInputStream fis = new FileInputStream("credentials.ini");
                credentials.load(fis);
                fis.close();
    
                return credentials;
            } catch (Exception e) {
                System.err.printf("FEHLER BEIM AUSLESEN DER ZUGANGSDATEN\n");
            }
    
            return null;
        }
    
        /**
         * Default Username for Basic Authentication
         *
         * @return String
         */
        public String getLogin() {
            return this.login;
        }
    
        /**
         * Default Password for Basic Authentication
         *
         * @return String
         */
        public String getPassword() {
            return this.password;
        }
    
        /**
         * Private Username for accessing the Remote Services
         *
         * @return String
         */
        public String getServiceLogin() {
            return this.serviceLogin;
        }
    
        /**
         * Private Password for accessing the Remote Services
         *
         * @return String
         */
        public String getServicePassword() {
            return this.servicePassword;
        }
    
    }
    

    Erstellen Sie eine neue Klasse SampleClient.java im Client Package mit Main-Methode

    Erstellung Client Class

    Listing SampleClient.java

    /**
     * SampleClient for otela Enterprise Systems
     *
     * The MIT License (MIT)
     *
     * @copyright Copyright(C) 2016 otela Enterprise Systems
     * @author    Markus Bröker<markus.broeker@otela.net>
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in all
     * copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     */
    package de.otela.soap.client;
    
    import de.otela.soap.server.Credentials;
    import de.otela.soap.server.CustomerServiceBindingStub;
    import de.otela.soap.server.CustomerServicePort;
    import de.otela.soap.server.CustomerServicePortProxy;
    
    public class SampleClient {
    
        public static void main(String[] args) {
            CustomerServicePortProxy proxy = new CustomerServicePortProxy();
            CustomerServicePort port = proxy.getCustomerServicePort();
    
            try {
                CustomerServiceBindingStub binding = (CustomerServiceBindingStub) port;
    
                ApiKey key = new ApiKey();
    
                binding.setUsername(key.getServiceLogin());
                binding.setPassword(key.getServicePassword());
    
                Credentials credentials = new Credentials(key.getLogin(), key.getPassword());
    
                /* Use the Webservice */
            } catch (Exception e) {
                System.out.println("Ausnahme: " + e.getLocalizedMessage());
            }
        }
    
    }
    

Programmiersprache PHP5 mit Netbeans

Erstellen Sie ein neues PHP-5 Projekt und erzeugen Sie eine neue Klasse Credentials.php.
Fügen Sie die beiden Listings in Credentials.php und in die von Netbeans automatisch erzeugte index.php ein.

Führen Sie das Projekt aus. Sie erhalten eine Übersicht der implementierten Webdienste.


Netbeans mit Ausgabe




Listing Credentials.php

<?php

/**
 * WebServices for otela Enterprise Systems
 *
 * @copyright Copyright(C) 2016 otela Enterprise Systems
 * @author    Markus Bröker<markus.broeker@otela.net>
 */
class Credentials {

    /**
     *
     * @var string
     */
    public $login;

    /**
     *
     * @var string
     */
    public $password;

}

Listing SampleClient.php

<?php

/**
 * Sample Client for otela Enterprise Systems
 *
 * @copyright Copyright(C) 2016 otela Enterprise Systems
 * @author    Markus Bröker<markus.broeker@otela.net>
 */

require_once 'Credentials.php';

// Plain Text Ausgabe
header('Content-Type: text/plain; charset=utf-8');

// WSDL Caching deaktivieren
ini_set("soap.wsdl_cache_enabled", 0);

// Erzwinge UTF-8 Encoding
ini_set('mb_internal_encoding', 'UTF-8');

define("WITH_BASIC_LOGIN", true);

if (defined('WITH_BASIC_LOGIN')) {
    define("BASIC_LOGIN", "");
    define("BASIC_PASSWORD", "");
}

define('WSDL_URL', 'https://soap.otela.de/server/server.wsdl');

try {
    $credentials = new Credentials();
    $credentials->login = "";
    $credentials->password = "";

    $options = array(
        'soap_version' => SOAP_1_1,
        'trace' => true,
        'exceptions' => true,
    );

    if (defined('WITH_BASIC_LOGIN')) {
        $options['login'] = BASIC_LOGIN;
        $options['password'] = BASIC_PASSWORD;
    }

    // Proxy initialisieren
    $proxy = new SoapClient(WSDL_URL, $options);

    /* Use the Webservice */

    printf("   REMOTE-Service: %s\n", WSDL_URL);
    printf("REMOTE-PROCEDURES: %s\n", print_r($proxy->__getFunctions(), true));
    printf("\n");

} catch (SoapFault $sf) {
    printf("%s\n", $sf);
} catch (InvalidArgumentExcpetion $iae) {
    printf("Ungültiges Argument: %s\n", $iae->getMessage());
    echo $iae->getTraceAsString();
} catch (Excpetion $e) {
    printf("Allgemeiner Fehler: %s\n", $e->getMessage());
    echo $e->getTraceAsString();
}

Programmiersprache C# mit Visual Studio Community 2015

Erstellen Sie ein neues C# Konsolen-Projekt und fügen Sie einen Dienstverweis "https://soap.otela.de/server/server.wsdl" hinzu.
Fügen Sie die beiden Listings in ApiKey.cs und in die von Visual Studio automatisch erzeugte Program.cs ein.


Visual Studio mit Dienstverweis


Listing ApiKey.cs

/**
 * Api-Key for otela Enterprise Systems
 *
 * The MIT License (MIT)
 *
 * @copyright Copyright(C) 2016 otela Enterprise Systems
 * @author    Markus Bröker<markus.broeker@otela.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.IO;

namespace ConsoleApplication1 {
    public class ApiKey {

        private String login;
        private String password;
        private String serviceLogin;
        private String servicePassword;

        public ApiKey() {
            Dictionary<String, String> data = this.parseProperties();

            this.login = data["login"];
            this.password = data["password"];
            this.serviceLogin = data["servicelogin"];
            this.servicePassword = data["servicepassword"];
        }

        /**
         * Liest eine Property-Datei "properties.ini" im Stammordner des Projekts ein.
         *
         */
        public Dictionary<String, String> parseProperties() {
            var data = new Dictionary<String, String>();

            foreach (var row in File.ReadAllLines("../../properties.ini")) {
                String[] property = row.Split('=');

                data.Add(property[0], property[1]);
            }

            return data;
        }

        /**
         * Liefert den aktuellen RPC-Benutzernamen
         *
         */
        public String GetLogin() {
            return this.login;
        }

        /**
         * Liefert das aktuelle RPC-Passwort
         *
         */
        public String GetPassword() {
            return this.password;
        }

        /**
         * Liefert den aktuellen Benutzernamen für die Basic-Authentifizierung
         *
         */
        public String GetServiceLogin() {
            return this.serviceLogin;
        }

        /**
         * Liefert das aktuelle Passwort für die Basic-Authentifizierung
         *
         */
        public String GetServicePassword() {
            return this.servicePassword;
        }
    }
}

Listing Program.cs

/**
 * Sample Client for otela Enterprise Systems
 *
 * The MIT License (MIT)
 *
 * @copyright Copyright(C) 2016 otela Enterprise Systems
 * @author    Markus Bröker<markus.broeker@otela.net>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
using System;
using System.Net;
using System.ServiceModel;

using ConsoleApplication1.ServiceReference1;

namespace ConsoleApplication1 {

    class otelaClient : CustomerServicePortClient {

        public otelaClient(String username, String password) : base(GetBinding(), GetEndpoint()) {
            ServicePointManager.Expect100Continue = false;

            ClientCredentials.UserName.UserName = username;
            ClientCredentials.UserName.Password = password;
        }

        /**
         * Private Hilfsmethode zum Initialisieren der Basic Authentifizierung via SSL
         *
         */
        private static BasicHttpBinding GetBinding() {
            // Setzten der Transportsicherheit für otela Enterprise Systems
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            // Erhöhen der maximalen Nachrichtenlänge von 64 kb auf 320 MB
            binding.MaxReceivedMessageSize = 320 * 1024 * 1024;

            return binding;
        }

        /**
         * Private Hilfsmethode zum Überschreiben des Service-Endpoints /server/ auf /server/index.php
         */
        private static EndpointAddress GetEndpoint() {
            EndpointAddress endpoint = new EndpointAddress("https://soap.otela.de/server/index.php");

            return endpoint;
        }

    }

    class Program {
        static void Main(string[] args) {

            // ApiKey instanzieren
            ApiKey key = new ApiKey();

            // otelaClient instanzieren
            otelaClient client = new otelaClient(key.GetServiceLogin(), key.GetServicePassword());

            try {

                Credentials credentials = new Credentials();
                credentials.login = key.GetLogin();
                credentials.password = key.GetPassword();

                /* Use the Webservice */

            } catch (FaultException fe) {
                System.Console.WriteLine("Service Error" + fe.Code);
            }

            System.Console.ReadKey();
        }
    }
}