lunedì 29 febbraio 2016

Made a SOAP WebService client using Oracle PL/SQL

This simple script allow you to made a webservice client that runs on Oracle database.



  • Take the pl/sql script that you find below and change it to call your webservice, you will see the output in the standard output.


declare
    l_response_payload  XMLType;
    l_payload           varchar2(2000);
    l_payload_namespace varchar2(200);
    l_target_url        varchar2(200);

    l_soap_request  varchar2(30000);
    l_soap_response varchar2(30000);
    http_req        utl_http.req;
    http_resp       utl_http.resp;
begin

    --l_payload_namespace := 'http://tempuri.org/';
    l_target_url        := 'http://www.webservicex.net/CurrencyConvertor.asmx';
    l_soap_request      :=  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                               xmlns:web="http://www.webserviceX.NET/">
                               <soapenv:Header/>
                               <soapenv:Body>
                                  <web:ConversionRate>
                                     <web:FromCurrency>USD</web:FromCurrency>
                                     <web:ToCurrency>EUR</web:ToCurrency>
                                  </web:ConversionRate>
                               </soapenv:Body>
                            </soapenv:Envelope>';

    http_req       := utl_http.begin_request(l_target_url,
                                             'POST',
                                             'HTTP/1.1');
                                                                                    
    utl_http.set_header(http_req, 'Content-Type', 'text/xml');
    utl_http.set_header(http_req, 'Content-Length', length(l_soap_request));
    --utl_http.set_header(http_req, 'SOAPAction', p_soap_action);
   
    --
    --Sumit the request and get response
    --
    utl_http.write_text(http_req, l_soap_request); 
    http_resp := utl_http.get_response(http_req);
    utl_http.read_text(http_resp, l_soap_response);
    utl_http.end_response(http_resp);

    -- only return the payload from the soap response - that is: the content of the body element in the SOAP envelope
    l_response_payload :=  XMLType.createXML(l_soap_response) .extract('/soap:Envelope/soap:Body/child::node()',
                                                                       'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"');
    
    --
    --PRINTOUT THE RESPONSE
    --
    dbms_output.put_line(l_response_payload.getStringVal());
    dbms_output.put_line('ConversionRateResult->' ||
    trim(l_response_payload.extract('/ConversionRateResponse/ConversionRateResult/text()',
                                    'xmlns="http://www.webserviceX.NET/"').getStringVal()));

end;



sabato 6 febbraio 2016

Play with Serial Ports

When you have to write a software that interact with a device using the serial port,  one of the problem is the simulation of it on the same pc without phisically connect to the phisical device.


Eltima Virtual Serial Port

A good closed source software that help us is in this case is Eltima Virtual Serial Port, this enable us to connect togeder two virtual serial port (virtual port pair).

So all what we will write on COM20 for example is redirected to COM21 and vice-versa so we can simulate the data traffic between our program and the device.

You can downlad the tryal install at http://www.eltima.com/products/vspdxp/




Realterm

This good open source software is a serial port terminal with multiple advanced functions (for electronic guys), you can connect directly to a serial por, type some text into it and , one of the feature that I apreciate is the logging function that write all the data received into a text file.

You can downlad the install at sourceforge :
http://sourceforge.net/projects/realterm/?source=typ_redirect



Here in this video you can see the Ethima Virtual Serial Port in action with Realterm.