Web 1:5000 - Gipuzkoa Provincial Council

implementation-of-web-service-client-applications-contents (PDF download)

1 Description of the Document

This document describes the prototypes of SOAP API consumer applications packages developed as integration examples of the Spatial SOAP API in the current version of the platform.

It describes the implemented prototypes and acts as a manual to develop other client applications packages in different development platforms.

It describes four client applications package prototypes in four different technologies, that demonstrate the interoperability of the SOAP API..

The four technologies that implemented the prototypes are: .Net, Java, a Web client and php.

There is a prototype developed in .Net which implements the use of the whole functionality served by the different SOAP API of the Platform (See http://b5m.gipuzkoa.net/appws/publish.htm ). Due to its complexity, a reduced prototype is described in this document.

Return to Index

2.1 Introduction

The development of the client in Microsoft .Net platform has been performed with the Visual Studio 2005 development environment and the C# programming language. The described prototype accesses to the Localizar por ID SOAP API.

Return to Index

2.2 Creating a consumer application package for the"Localizar por ID" SOAP API

2 .Net client application package

2.2 Creating a consumer application package for the"Localizar por ID" SOAP API

Add New Data Source option

The first window of the Wizard will appear.

Wizard will appear

Select the "SOAP API" option and the "Next" button and the following web reference window will appear.

SOAP API option

In the URL text box, enter the URL of the WSDL file for the SOAP API that tallies with the SOAP API to be used.

http://b5m.gipuzkoa.net/dfg-localizar-context-root/LocalizarPorIdSoapHttpPort?WSDL

After a few seconds, a list of the methods that the service has available will appear.

URL of the WSDL file

Select the "Add Reference" and the following window appears

Select the Add Reference

When you select "Finish", the Wizard window closes and the new reference is added to the solution and the "Data Source" created.

The new web reference will appear in the "Solution Explorer" window.

Solution Explorer window

When you select the "Data->Show Data Sources" option from the menu, the Data Sources window will appear.

Data Sources window

A Data Source appears for each output variable of the SOAP API that can be opened to explore the data structure.

Return to Index

2.2.1 Add controls to the application package

In order to view the SOAP API response, a DataGrid can be added by dragging the icon from the Data Source to the form. In the example, the "LocalizarPorIdUser_localizaridcallejero_Out -> objectOut ->listaDirecciones" structure is dragged from the service to the form.

In the example, the LocalizarPorIdUser_localizaridcallejero_Out -> objectOut ->listaDirecciones structure is dragged from the service to the form

A Button type control is added to call the SOAP API.

Button type control

Return to Index

2.2.2 C# Code

The access code to the SOAP API is added to the "button1_Click" method. Double clicking on the design mode button creates the empty class in codification mode.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{

   public partial class Form1 : Form
       { public Form1()
         
             {
            InitializeComponent();
             }
             private void button1_Click(object sender, EventArgs e)        
             {
            
             }
        }
}

Add the following the code lines to the button1_Click() method.

private void button1_Click(object sender, EventArgs e)
{

       // Create a new instance of the SOAP API class.
       net.gipuzkoa.b5m.LocalizarPorId webId =
               new net.gipuzkoa.b5m.LocalizarPorId();

       // Additional layer to null array.
       net.gipuzkoa.b5m.WsmapasselectUser[] nomArr = null;
       // Call the SOAP API and collect the response.
        net.gipuzkoa.b5m.LocalizarPorIdUser_localizaridcallejero_Out
               webIdOut=webId.localizaridcallejero("D_4545","","0","Si",
                      "PUBLI", "200", "200", "NO", nomArr);
        // Assign the response to the DataSource.
        listaDireccionesBindingSource.DataSource =
               webIdOut.objectOut.listaDirecciones;
}

Return to Index

2.2.3 Test the Example

Run the application, select the button to launch the request to the SOAP API and after a few seconds, the service response will appear in the Grid.

Button to launch the request

Return to Index

2.2.4 Expand the Example

With the Imagen="Si" parameter, the service has generated an image that tallies with the id "D-4545" that has been used. In this section, the example will be expanded to draw the image.

You first have to the form in design mode and add a PictureBox that is used to display the map and a TextBox to introduce the identifier of the building.

You first have to the form in design mode

The modified method to process the image will then appear. The code has also been modified to clear the image and the DataSource and the status of the cursor is updated while the service is executed.

private void button1_Click(object sender, EventArgs e)
{
      // Change cursor..
      Cursor.Current = Cursors.WaitCursor;

      // Clear DataSource
      listaDireccionesBindingSource.Clear();

     // Clear image
     if (pictureBox1.Image != null)
        pictureBox1.Image =
null;
     Refresh();

      // Create a new instance of the SOAP API class
     net.gipuzkoa.b5m.LocalizarPorId webId = new
      net.gipuzkoa.b5m.LocalizarPorId();


      // Additional layer to null array.
      net.gipuzkoa.b5m.WsmapasselectUser[] nomArr = null;

      // Call the SOAP API and collect the response.
      net.gipuzkoa.b5m.LocalizarPorIdUser_localizaridcallejero_Out
            webIdOut = webId.localizaridcallejero (richTextBox1.Text,
                  "", "0", "Si", "VITO",
                 pictureBox1.Width.ToString(),
                  pictureBox1.Height.ToString(), "NO", nomArr);

      // Assign the response to the DataSource.
      listaDireccionesBindingSource.DataSource =
          webIdOut.objectOut.listaDirecciones;

      // Collect the image URL
     string IdCallUrl = Convert.ToString(webIdOut.imagenurlOut);

      // Request and draw the map
     if (webIdOut.imagenurlOut != null)
      {
        WebRequest WReq = WebRequest.Create(IdCallUrl);
       WebResponse WRes = WReq.GetResponse();
        Stream strm = WRes.GetResponseStream();
        Image WImage =        Image.FromStream(strm);
       pictureBox1.Image = WImage;
      }

      // Leave the default cursor.
     Cursor.Current = Cursors.Default;
}

In addition, the following namespaces to the project have to be added.

using System.Net;

using System.IO;

Return to Index

2.2.5 Test the Extended example

Run the new version of the example and the map will appear focused on the building that tallies with the ID.

Test the Extended example

When the ID is changed and the service launched, the data of the previous request is deleted. The data and image of the new request will appear after a few seconds.

Data and image of the new request

Return to Index

3 Java client application package

3.1 Introduction.

In this case, the implementation in Java is described of a client that uses a SOAP API also using the WSDL description archive

Return to Index

3.2 Requirements

The ECLIPSE WTP PROJECT software is used to generate client classes using the WSDL description archive. This software may be downloaded from:

http://www.eclipse.org/webtools/main.html

The above project includes all the necessary plugins and the Eclipse platform. The JVM required is 1.5.

http://java.sun.com/j2se/1.5.0/download.jsp

In both cases, the installation instructions described in the given URLs have to be followed.

Return to Index

3.3 Processes to be implemented

Once it is installed, the J2EE perspective is accessed from the Eclipse platform:

J2EE perspective is accessed from the Eclipse platform

A new project is created in the following file: Dynamic Web Projets

In this case DFGWeb and we put the wsdl description file in the WSDL directory. Once selected using the right button, as is shown in the figure, the following classes are generated:

classes are generated

The process generates the necessary classes to check the service, as well as registering jsp pages to be checked in the servers.

the necessary classes to check the service

A Java project is generated to check the service:

Java project is generated to check the service

The class is WSExecutor.java that can be executed.

Return to Index

3.4 Source Code

3.4.1 WSExecutor.java

Main

   public static void main(String[] args) {

       WSExecutor we = new WSExecutor();      

       we.testTopo();

    }

Perform the testTopo test:

    private void testTopo() {

      String topo = "DONOXTI";

       String lengua = "0";

       boolean bprint = true;

       try {

            WstopobjUser[] wu = dooToponimo(topo, lengua);

             if (bprint == true) {

               printData(wu);

             }

       } catch (Exception e) {

            e.printStackTrace();

       }

    }

and the Toponimo function:

   public WstopobjUser[] dooToponimo(String topo, String lengua) throws RemoteException {

      //array of objects to be returned

       WstopobjUser[] wu = null;

      // The proxy is created

      BuscartoponimoProxy btp = new BuscartoponimoProxy();

      //The parameters are created

      Buscartoponimo parameters = new Buscartoponimo();

   //Values are assinged

      parameters.setToponimo(topo);

      parameters.setLengua(lengua);

      //the service is executed

      BuscartoponimoResponse bpr = btp.buscartoponimo(parameters);

      //the result is obtained

      BuscartoponimoUser_buscartoponimo_Out bubo = bpr.getResult();

      BigDecimal bd = bubo.get_return();

      wu = bubo.getToponimoarrOut();

      return wu;

    }

Return to Index

4 Web client

AJAX technology allows web applications with a high degree of dynamism to be developed. Broadly speaking, it consists of a script language (Javascript, Jscript,...) being used on the client side to perform XML requests to a server that contains the logics of the application.

AJAX can therefore be used to make calls to SOAP API. The steps to be performed to implement a website the uses JavaScript to make a call a SOAP API of the platform are listed below.

Specifically, the SOAP API is used to locate an item by its ID and the building with ID D_4545, which is searched in the street plan topic. The search language will be Spanish.

The locate object SOAP API is waiting an XML request with the following format:

   <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

       <soap:Body xmlns:ns1="http://com/dfg/webservices/LocalizarPorId.wsdl/types/">

           <ns1:localizaridcallejeroElement>

           <ns1:identificador>D_4545</ns1:identificador>

           <ns1:escala>12000</ns1:escala>

           <ns1:lengua>0</ns1:lengua>>

           <ns1:imagen>si</ns1:imagen>

           <ns1:escenario>VITO</ns1:escenario>

           <ns1:anchura>640</ns1:anchura>

           <ns1:altura>480</ns1:altura>

           </ns1:localizaridcallejeroElement>

       </soap:Body>

   </soap:Envelope>

Therefore, the first step to be performed in Javascript would be to create the XML document that will be sent to the SOAP API:

var xmlDoc = createNewDocument();

The following step would be to put the heading in the XML:

var envelope = createElementNS(xmlDoc, 'http://schemas.xmlsoap.org/soap/envelope/', 'Envelope');

xmlDoc.appendChild(envelope);

var body = createElementNS(xmlDoc,

'http://schemas.xmlsoap.org/soap/envelope/', 'Body');

envelope.appendChild(body);

var parameterParent = body;

parameterParent = createElementNS(xmlDoc,

'http://com/dfg/webservices/LocalizarPorId.wsdl/types/',

'localizaridriosElement');

body.appendChild(parameterParent);

The createElementNS() and appendChild() functions create the XML structure. CreateElementNS() is used to create a new element in the document and appendChild() to establish the correct hierarchical order within the document.

The following step would be allocate the values to each of the parameters that the SOAP API requires. In the case of the building identifier, it would be:

paramEl.appendChild(xmlDoc.createTextNode(D_4545));

parameterParent.appendChild(paramEl);

The previous step needs to be performed for each of the parameters of the request (language, image, scenario...).

In this point, the XML document has been created and would appear as follows when displayed on the web page:

XML document

The following step is to perform the call to the SOAP API that sends the XML that have been created. The XmlHttpRequest object, which is implemented by the majority of browsers, can be used to send XML from Javascript.

The XmlHttpRequest item is created in different forms depending on the Internet browser being used. The following code would generate the desired item:

   var req = null;

   if (window.XMLHttpRequest) { // Si no es Internet Explorer

      req = new XMLHttpRequest();

   } else if (window.ActiveXObject) { //Si es Internet Explorer

       req = new ActiveXObject("Microsoft.XMLHTTP");

   }

Once created, it is then configured. First, the type of request to be performed (GET or POST) is established and the URL where the SOAP API is located.

req.open("POST", url, false);

Then, the required "Content-Type" is then configured, in this case "text/xml".

req.setRequestHeader("Content-Type", "text/xml");

Finally, the XML is then sent using the send() function,

req.send(xmlDoc);

All the above call be grouped in a function that receives the URL where the SOAP API is located and the XML to be sent and returns the service response. The indicated code would be:

   function invokeSync (url, xmlDoc) {

      var req = null;

      if (window.XMLHttpRequest) { // Si no es Internet Explorer

         req = new XMLHttpRequest();

      } else if (window.ActiveXObject) { //Si es Internet Explorer

         req = new ActiveXObject("Microsoft.XMLHTTP");

      }

      if (req) {

          req.open("POST", url, false);

         req.setRequestHeader("Content-Type", "text/xml");

          req.send(xmlDoc);

          return req.responseXML;

      }

   }

If the SOAP API is called with the above parameters, the following would be returned:

   <?xml version="1.0" encoding="UTF-8"?>

   <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"

   xmlns:xsd="http://www.w3.org/2001/XMLSchema"

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:ns0="http://com/dfg/webservices/LocalizarPorId.wsdl/types/">

    <env:Body>

        <ns0:localizaridcallejeroResponseElement>

          <ns0:result>

              <ns0:imagenurlOut>

              http://arqfotos:9876/internet/GenaImageSourcer? ?

              IMAGEID=164566151176& RETCONTENTTYPE=image/png&RM=FALSE </ns0:imagenurlOut>

            <ns0:return>OK</ns0:return>

             <ns0:objectOut>

                        <ns0:listaDirecciones>

                         <ns0:array>

                        <ns0:nombre>SALESIANOS, CONVENTO</ns0:nombre>

                        <ns0:seccion>002</ns0:seccion>

                         <ns0:numero>012 </ns0:numero>

                        <ns0:terminoMunicipal xsi:nil="1"/>

                         <ns0:nucleoUrbano xsi:nil="1"/>

                        <ns0:distrito>02</ns0:distrito>

                         <ns0:municipio>AZKOITIA | 017</ns0:municipio>

                         <ns0:codigoPostal>20720</ns0:codigoPostal>

                        <ns0:comarca xsi:nil="1"/>

                        <ns0:calle>AIZKIBEL KALEA | 1240</ns0:calle>

                         </ns0:array>

               </ns0:listaDirecciones>

               <ns0:listaActividades xsi:nil="1"/>

               </ns0:objectOut>

               </ns0:result>

                </ns0:localizaridcallejeroResponseElement>

               </env:Body>

            </env:Envelope>

The XML returned by the SOAP API could be analysed in Javascript in order to obtain information and show it appropriately on a web page or it can simply display the returned XML:

display the returned XML

Finally, the complete code is displayed of the functions used in this document to perform the petition and a new main function that performs the whole process. The function is LocalizarPorIdSoapHttpPort_localizaridcallejero() and receives the necessary data as parameters to perform the SOAP API request, generates the necessary XML, sends it to the service and finally, it returns the XML response of the server.

  function LocalizarPorIdSoapHttpPort_localizaridcallejero(_identificador, _escala, _lengua, _imagen, _escenario, _anchura, _altura) {

      var xmlDoc = createNewDocument();

      var envelope = createElementNS(xmlDoc, 'http://schemas.xmlsoap.org/soap/envelope/', 'Envelope');

      xmlDoc.appendChild(envelope);

      var body = createElementNS(xmlDoc, 'http://schemas.xmlsoap.org/soap/envelope/', 'Body');

      envelope.appendChild(body);

      var parameterParent = body;

      parameterParent = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'localizaridcallejeroElement');

       body.appendChild(parameterParent);

        var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'identificador');

        paramEl.appendChild(xmlDoc.createTextNode(_identificador));

       parameterParent.appendChild(paramEl);

        var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'escala');

        paramEl.appendChild(xmlDoc.createTextNode(_escala));

        parameterParent.appendChild(paramEl);

       var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'lengua');

       paramEl.appendChild(xmlDoc.createTextNode(_lengua));

       parameterParent.appendChild(paramEl);

       var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'imagen');

       paramEl.appendChild(xmlDoc.createTextNode(_imagen));        parameterParent.appendChild(paramEl);

       var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'escenario');

       paramEl.appendChild(xmlDoc.createTextNode(_escenario));        parameterParent.appendChild(paramEl);

       var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'anchura');

       paramEl.appendChild(xmlDoc.createTextNode(_anchura));       parameterParent.appendChild(paramEl);

      var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'altura');

       paramEl.appendChild(xmlDoc.createTextNode(_altura));

       parameterParent.appendChild(paramEl);

       var responseDoc = invokeSync('http://arqfotos:8888/dfg-loid/LocalizarPorIdSoapHttpPort', xmlDoc);

       return responseDoc;

      }

  function createElementNS (xmlDoc, namespace, localName) {

    var element = null;

    if (typeof xmlDoc.createElementNS != 'undefined') {

       element = xmlDoc.createElementNS(namespace, localName);

    }

     else if (typeof xmlDoc.createNode != 'undefined') {

       if (namespace) {

       element = xmlDoc.createNode(1, localName, namespace);

       } else {

       element = xmlDoc.createElement(localName);

     }

    }

     return element;

  }



  function createNewDocument () {

       var xmlDoc = null;

      if (document.implementation && document.implementation.createDocument) {

       xmlDoc = document.implementation.createDocument("", "", null);

       } else if (window.ActiveXObject){

       xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

       }

       return xmlDoc;

  }

  function invokeSync (url, xmlDoc) {

      var req = null; if (window.XMLHttpRequest) {

       req = new XMLHttpRequest();

       } else if (window.ActiveXObject) {

       req = new ActiveXObject("Microsoft.XMLHTTP");

      }

      if (req) {

       req.open("POST", url, false);

       req.setRequestHeader("Content-Type", "text/xml");

       req.send(xmlDoc);

       return req.responseXML;

      }

  }

Return to Index

5 PHP client application package

5.1 Introduction

In this case, the implementation in PHP is described of a client that uses a SOAP API also using the WSDL description archive.

Return to Index

5.2 Requirements

PHP Version 5.1.2.

NUSOAP version 0.7.2. library (http://sourceforge.net/projects/nusoap)

Return to Index

5.3 Source Code

Example 1: Call the SOAP API to draw the map

   <?php

   // Load the libraries.

   require_once('./lib/nusoap.php');

   // Production

   $wsdl="http://b5m.gipuzkoa.net/ws/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL";

   // Read the WSDL and create the proxies

   $client=new soapclient($wsdl, 'wsdl');

   // Change the URL endpoint to $wsdl less the last 5 characters

   $client->operations['dibujarimagen']['endpoint'] = substr($wsdl,0,strlen($wsdl)-5);

   // Force the char sets.

   $client->soap_defencoding = 'UTF-8';

   $client->decode_utf8 = false;

   // Layer control example.

   $mapasel=array('nombre'=>'L%EDmites municipales','estado'=>'n','tipo'=>'Mapa');

   // Parameter Example.

   $params=array(array('ix1'=>'540000','iy1'=>'4740000','ix2'=>'610000','iy2'=>'4810000','iwidth'=>'500','iheight'=>'300','iescenario'=>'PUBLI','lengua'=>'0','mapaselectarr'=>$mapasel));

   // Error check.

   $err = $client->getError();

   if ($err) {

            echo 'Constructor error' . $err ;

   }

   // Call SOAP API.

   $result = $client->call('dibujarimagen', $params);

   // Error check.

   if ($client->fault) {

           echo 'Fault'; print_r($result);

   } else {

          $err = $client->getError();

          if ($err) {

               echo 'Error' . $err ;

          }

   }

   // See the results

   print_r($result);

   // Debugging tools

   //echo $client->response;

   //echo $client->request;

   //echo $client->debug_str;

   ?>

if the PHP example is executed from a UNIX shell, the following result will be seen.

   $ php dib.php

   Array

   (

       [result] => Array

           (

            [return] => 1

            [oimagepathOut]=>

http://b5m.gipuzkoa.net/internet/GenaImageSourcer?IMAGEID=2034743655&RETCONTENTTYPE=image/png

       )

   )

To recover the image, a http request with the URL given in the oimagepathOut variable is executed.

Example 2: Call the SOAP API to see the available layers.

   <?php

   // Load the libraries.

   require_once('./lib/nusoap.php');

   // Production

   $wsdl="http://b5m.gipuzkoa.net/ws/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL";

   // Read the WSDL and create the proxies

   $client=new soapclient($wsdl, 'wsdl');

   // Change the URL endpoint to $wsdl less the last 5 characters

   $client->operations['mapasdisponibles']['endpoint'] = substr($wsdl,0,strlen($wsdl)-5);

   // Force the char sets.

   $client->soap_defencoding = 'UTF-8';

   $client->decode_utf8 = false;

   // Parameter Example.

   $params1=array(array('categoria'=>'PUBLI','lengua'=>'0'));

   // Error check.

   $err = $client->getError();

   if ($err) {

         echo 'Constructor error' . $err ;

   }

   // Call SOAP API.

   $result = $client->call('mapasdisponibles', $params1);

   if ($client->fault)

   {

          echo 'Fault'; print_r($result);

   }

   else

   {

           $err = $client->getError();

           if ($err)

          {

             echo 'Error' . $err ;

          }

   else

   {

             // See the results

              print_r( $result ) ;

          }

   }

   ?>

If the PHP example is executed from a UNIX shell, the following result will be seen.

   $ php mapas.php

   Array

   (

   [result] => Array

   (

       [return] => Array

         (

            [wsmessage] => OK

            [wsstatus] => 5

         )

         [objectOut] => Array

            (

            [0] => Array

            (

               [MActivado] => s

               [GActivado] => S

               [clase] => AltimetrA­a

               [grupo] => Nada

               [descripcion] => AltimetrA­a 100

               [mapa] => alti_100

               [CActivado] => S

         )

      [1] => Array

         (

                [MActivado] => s

                [GActivado] => S

                [clase] => AltimetrA­a

                [grupo] => Nada

                [descripcion] => AltimetrA­a 25

                [mapa] => alti_25

                [CActivado] => S

         )

       .

       .

       .

     )

    )

 )

 $ php mapas.php

   Array

       (

           [result] => Array

        (

           [return] => Array

                     (

          [wsmessage] => OK

          [wsstatus] => 5

                     )

                              [objectOut] => Array

                    (

          [0] => Array

                    (

               [MActivado] => s

               [GActivado] => S

                [clase] => AltimetrA­a

                [grupo] => Nada

               [descripcion] => AltimetrA­a 100

               [mapa] => alti_100

                [CActivado] => S

            )

      [1] => Array

           (

               [MActivado] => s

               [GActivado] => S

               [clase] => AltimetrA­a

                [grupo] => Nada

                [descripcion] => AltimetrA­a 25

                [mapa] => alti_25

                [CActivado] => S

            )

               .

               .

               .

               )

        )

   )

Return to Index

6 PDA Windows Mobile Application Package

6.1 Introduction

The development of PDA client has been performed with the Microsoft .Net Compact Framework 2.0 with the Visual Studio 2005 development environment and the C# programming language. The described prototype accesses to the DibujarImagen SOAP API.

Return to Index

6.2 Creating the PDA project

In order to create a project for a PDA, a "Device Application" type project is created.

Device Application type project

When you select "OK", a form appears in a PDA image.

Form appears in a PDA image.

Return to Index

6.3 Creating a consumer application package for the "DibujarImagen" SOAP API

Select "Add New Data Source" option from the Data menu.

Data Menu

The first window of the Wizard will appear.

window of the Wizard

Select the "SOAP API" option and the "Next" button and the following web reference window will appear.

SOAP API

In the URL text box, enter the URL of the WSDL file for the SOAP API that tallies with the SOAP API to be used.

Example: Dibujar.

http://b5m.gipuzkoa.net/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL

After a few seconds, a list of the methods that the service has available will appear.

list of the methods that the service has available

Select the "Add Reference" and the following window appears.

Add Reference and the following window

When you select "Finish", the Wizard window closes and the new reference is added to the solution and the "Data Source" creates.

Return to Index

6.3.1 Add controls to the application package

A Button type control is added to launch the SOAP API and a PictureBox type control is added to view the result.

launch the SOAP API

Return to Index

6.3.2 C# Code

The access code to the SOAP API is added to the "button1_Click" method. Double clicking on the design mode button creates the empty class in codification mode.

   using System;

   using System.Collections.Generic;

   using System.ComponentModel;

   using System.Data;

   using System.Drawing;

   using System.Text;

   using System.Windows.Forms;

   namespace DeviceApplication1

         {

          public partial class Form1 : Form

          {

             public Form1()

         {

          InitializeComponent();

         }

       private void button1_Click(object sender, EventArgs e)

      {

      }

    }

 }

Add the following the code lines to the button1_Click() method.

 private void button1_Click(object sender, EventArgs e)

  {


       // Additional layer to null array.

    net.gipuzkoa.b5m.WsmapasselectUser[] userArray1 = null;

    Cursor.Current = Cursors.WaitCursor;


      // Create a new instance of the SOAP API class.

    net.gipuzkoa.b5m.Dibujar webDibImg =

    new net.gipuzkoa.b5m.Dibujar();


      // Call the SOAP API and gather the response.

    net.gipuzkoa.b5m.DibujarUser_dibujarimagen_Out out1 =

     webDibImg.dibujarimagen("520000","4740000","610000",

         "4810000", pictureBox1.Width.ToString(),

          pictureBox1.Height.ToString(),

         "PUBLI", "0", userArray1);}

       // Request and draw the map

     Uri uri1 = new Uri(out1.oimagepathOut);

     HttpWebRequest request1 =

          (HttpWebRequest)WebRequest.Create(uri1);

     HttpWebResponse response1 =

          (HttpWebResponse)request1.GetResponse();

     StreamReader reader1 = new

          StreamReader(response1.GetResponseStream());

     Bitmap bitmap1 = new Bitmap(reader1.BaseStream);

     pictureBox1.Image = bitmap1;

     reader1.Close();

     Cursor.Current = Cursors.Default;

  }

Return to Index

6.3.3 Test the example with the emulator

When the application is executed, the following deploy window will appear.

he following deploy window will appear

Select the "Pocket PC 2003 SE Emulator" option and the "Deploy" button. The software will be installed in the emulator and a window will appear with the application running.

The software will be installed in the emulator and a window

In order to establish the Internet connection, the physical connection is emulated with ActiveSync, which is carried out using the "Device Emulator Manager" run from the "Tools" menu.

Device Emulator Manager

Once the "Emulator Manager" is running, select the "Pocket PC 2003 SE Emulator" option and then using the right button, select the "Cradle" option.

Pocket PC 2003 SE Emulator

The ActiveSync icon will change from grey to green and the association window will appear where the "Guest" option can be selected. Once connected, select the button to launch the request to the SOAP API and after a few seconds, an image of Gipuzkoa will appear.

image of Gipuzkoa

Return to Index

B5m.gipuzkoa.net home page.
  | Gipuzkoa.net   | Department of Environment and Planning     © 1997-2012