Nie pokazuj więcej tej informacji

Szanowny Kliencie!

Informujemy, że aby świadczyć usługi na najwyższym poziomie, nasz serwis internetowy gromadzi i zapisuje w pamięci komputerów Użytkowników serwisu krótkie informacje tekstowe (tzw. „cookies”). W dowolnym momencie istnieje możliwość modyfikacji ustawień przeglądarki, aby wyłączyć ten mechanizm. Konfiguracja, która dopuszcza używanie cookies oznacza, że Użytkownicy wyrażają na powyższe zgodę. Aby dowiedzieć się więcej proszę zapoznać się z Polityką Plików Cookies.

Przykłady klientów

Poniżej znajdują się przykłady prostych aplikacji uruchamiających metodę odpowiedzialną za tworzenie przesyłki i zamawianie kuriera, napisane w technologiach .NET oraz JAVA.

.NET

  1. Otwieramy konsolę "Visual Studio Command Prompt".
  2. Uruchamiamy komendę
    wsdl https://dhl24.com.pl/webapi2
  3. Do projektu w Visual Studio dodajemy wygenerowany plik DHL24WebapiService.cs
  4. Dodajemy do projektu bibliotekę System.Web.Services
  5. Gotowe
 
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
 
namespace DHL24Example
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            DHL24WebapiService service = new DHL24WebapiService();
 
            Console.WriteLine("AuthData...");
            AuthData auth = new AuthData();
            auth.username = "testomir";
            auth.password = "testalski";
 
            Console.WriteLine("CreateShipmentRequest...");
            CreateShipmentRequest request = new CreateShipmentRequest();
            request.content = "Gra komputerowa";
 
            request.shipmentInfo = new ShipmentInfo();
            request.shipmentInfo.serviceType = "AH";
            request.shipmentInfo.dropOffType = "REGULAR_PICKUP";
            request.shipmentInfo.labelType = "LP";
 
            request.shipmentInfo.shipmentTime = new ShipmentTime();
            request.shipmentInfo.shipmentTime.shipmentDate = "2012-11-13";
            request.shipmentInfo.shipmentTime.shipmentStartHour = "12:00";
            request.shipmentInfo.shipmentTime.shipmentEndHour = "15:00";
 
            request.shipmentInfo.billing = new Billing();
            request.shipmentInfo.billing.shippingPaymentType = "SHIPPER";
            request.shipmentInfo.billing.paymentType = "BANK_TRANSFER";
            request.shipmentInfo.billing.billingAccountNumber = 1234567;
 
            request.pieceList = new Package[] { new Package() };
            request.pieceList[0].packageType = "ENVELOPE";
            request.pieceList[0].quantity = 1;
 
            request.ship = new Ship();
            request.ship.shipper = new Addressat();
            request.ship.shipper.address = new Address();
            request.ship.shipper.address.name = "Janek Kowalski";
            request.ship.shipper.address.postalCode = "00909";
            request.ship.shipper.address.city = "Warszawa";
            request.ship.shipper.address.street = "Leśna";
            request.ship.shipper.address.houseNumber = "9";
            request.ship.receiver = new Addressat();
            request.ship.receiver.address = new Address();
            request.ship.receiver.address.name = "Karol Bielecki";
            request.ship.receiver.address.postalCode = "02796";
            request.ship.receiver.address.city = "Warszawa";
            request.ship.receiver.address.street = "Wąwozowa";
            request.ship.receiver.address.houseNumber = "2";
            request.ship.receiver.address.apartmentNumber = "59";
 
            Console.WriteLine("call createShipment()...");
            CreateShipmentResponse response = service.createShipment(auth, request);
 
            Console.WriteLine("save response label to file...");
            byte[] pdfContent = Convert.FromBase64String(response.label.labelContent);
            File.WriteAllBytes("result.pdf", pdfContent);
 
            Console.WriteLine("end!");
        }
    }
}
 

JAVA

  1. Pobieramy i rozpakowujemy narzędzie apache-cxf
  2. Wywołujemy komendę:
    wsdl2java -autoNameResolution https://dhl24.com.pl/webapi2
  3. Wygenerowane źródła kopiujemy do katalogu z projektem
  4. Dodajemy do projektu biblioteki jar z katalogu apache-cxf-x.y.z\lib\endorsed
  5. Gotowe
 
package pl._3e.examples;
 
import java.io.FileOutputStream;
import java.io.IOException;
 
import javax.xml.bind.DatatypeConverter;
 
import pl.com.dhl24.webapi.provider.service.Address;
import pl.com.dhl24.webapi.provider.service.Addressat;
import pl.com.dhl24.webapi.provider.service.ArrayOfPackage;
import pl.com.dhl24.webapi.provider.service.AuthData;
import pl.com.dhl24.webapi.provider.service.Billing;
import pl.com.dhl24.webapi.provider.service.CreateShipmentRequest;
import pl.com.dhl24.webapi.provider.service.CreateShipmentResponse2;
import pl.com.dhl24.webapi.provider.service.Package;
import pl.com.dhl24.webapi.provider.service.Ship;
import pl.com.dhl24.webapi.provider.service.ShipmentInfo;
import pl.com.dhl24.webapi.provider.service.ShipmentTime;
import pl.com.dhl24.webapi.provider.service_html_ws_1.DHL24WebapiPort;
import pl.com.dhl24.webapi.provider.service_html_ws_1.DHL24WebapiService;
 
 
public class Dhl24Example {
 
    /**
    * @param args
    * @throws IOException
    */
    public static void main(String[] args) throws IOException {
 
        final DHL24WebapiPort service = new DHL24WebapiService().getDHL24WebapiPort();
 
        System.out.println("AuthData...");
        final AuthData auth = new AuthData();
        auth.setUsername("testomir");
        auth.setPassword("testalski");
 
        System.out.println("CreateShipmentRequest...");
        final CreateShipmentRequest request = new CreateShipmentRequest();
        request.setContent("Gra komputerowa");
 
        request.setShipmentInfo(new ShipmentInfo());
        request.getShipmentInfo().setServiceType("AH");
        request.getShipmentInfo().setDropOffType("REGULAR_PICKUP");
        request.getShipmentInfo().setLabelType("LP");
 
        request.getShipmentInfo().setShipmentTime(new ShipmentTime());
        request.getShipmentInfo().getShipmentTime().setShipmentDate("2012-11-13");
        request.getShipmentInfo().getShipmentTime().setShipmentStartHour("12:00");
        request.getShipmentInfo().getShipmentTime().setShipmentEndHour("15:00");
 
        request.getShipmentInfo().setBilling(new Billing());
        request.getShipmentInfo().getBilling().setShippingPaymentType("SHIPPER");
        request.getShipmentInfo().getBilling().setPaymentType("BANK_TRANSFER");
        request.getShipmentInfo().getBilling().setBillingAccountNumber(1234567);
 
        final Package pkg = new Package();
        pkg.setType("ENVELOPE");
        pkg.setQuantity(1);
 
        request.setPieceList(new ArrayOfPackage());
        request.getPieceList().getItem().add(pkg);
 
        request.setShip(new Ship());
        request.getShip().setShipper(new Addressat());
        request.getShip().getShipper().setAddress(new Address());
        request.getShip().getShipper().getAddress().setName("Janek Kowalski");
        request.getShip().getShipper().getAddress().setPostalCode("00909");
        request.getShip().getShipper().getAddress().setCity("Warszawa");
        request.getShip().getShipper().getAddress().setStreet("Leśna");
        request.getShip().getShipper().getAddress().setHouseNumber("9");
        request.getShip().setReceiver(new Addressat());
        request.getShip().getReceiver().setAddress(new Address());
        request.getShip().getReceiver().getAddress().setName("Karol Bielecki");
        request.getShip().getReceiver().getAddress().setPostalCode("02796");
        request.getShip().getReceiver().getAddress().setCity("Warszawa");
        request.getShip().getReceiver().getAddress().setStreet("Wąwozowa");
        request.getShip().getReceiver().getAddress().setHouseNumber("2");
        request.getShip().getReceiver().getAddress().setApartmentNumber("59");
 
        System.out.println("call createShipment()...");
        final CreateShipmentResponse2 response = service.createShipment(auth, request);
 
        System.out.println("save response label to file...");
        final byte[] content = DatatypeConverter.parseBase64Binary(response.getLabel().getLabelContent());
        final FileOutputStream file = new FileOutputStream("result.pdf", false);
        file.write(content, 0, content.length);
        file.close();
 
        System.out.println("end!");
    }
 
}